Main Page | Report this Page
Linux Forum Index  »  Linux Development - Applications  »  encrypt...
Page 1 of 1    

encrypt...

Author Message
zix...
Posted: Sat Sep 05, 2009 11:08 pm
Guest
Hi,
I am trying to use the encrypt API in linux. My code is like this
below:

#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define _GNU_SOURCE
#include <crypt.h>
#include <errno.h>
#include <string.h>

int main()
{
char str[64]="abcdef";
char *key;
errno=0;
key=(char *)calloc(64,1);
memset(key, 1, 20);
setkey(key);
encrypt(str,0);
printf("str mod is %s errno is %d\n", str, errno);
return 0;
}
I expected an ecrypted string, but I am gettign the output as:
str mod is errno is 0

where am i going wrong? any idea?

Thanks for the help.
zix
 
zix...
Posted: Sat Sep 05, 2009 11:44 pm
Guest
On Sep 6, 2:23 pm, Markku Kolkka <markku.kol... at (no spam) iki.fi> wrote:
Quote:
zix wrote:
I am trying to use the encrypt API in linux.
(...)
I expected an ecrypted string, but I am gettign the output as:
str mod is errno is 0

where am i going wrong? any idea?

encrypt() works on 64-bit blocks of data encoded in an array of 64
bytes, it doesn't handle C-style null terminated text strings. Read the
man page for encrypt().

--
Markku Kolkka
markku.kol... at (no spam) iki.fi

oops, thanks a lot..btw, how do i then encrypt/decrypt a string in
linux?
 
Markku Kolkka...
Posted: Sun Sep 06, 2009 3:23 am
Guest
zix wrote:

Quote:
I am trying to use the encrypt API in linux.
(...)
I expected an ecrypted string, but I am gettign the output as:
str mod is errno is 0

where am i going wrong? any idea?

encrypt() works on 64-bit blocks of data encoded in an array of 64
bytes, it doesn't handle C-style null terminated text strings. Read the
man page for encrypt().

--
Markku Kolkka
markku.kolkka at (no spam) iki.fi
 
John Hasler...
Posted: Sun Sep 06, 2009 6:21 am
Guest
Consider des_crypt instead.
--
John Hasler
john at (no spam) dhh.gt.org
Dancing Horse Hill
Elmwood, WI USA
 
zix...
Posted: Mon Sep 07, 2009 8:11 pm
Guest
On Sep 6, 5:21 pm, John Hasler <j... at (no spam) dhh.gt.org> wrote:
Quote:
Consider des_crypt instead.
--
John Hasler
j... at (no spam) dhh.gt.org
Dancing Horse Hill
Elmwood, WI USA



I am able to encrypt by crypt call. The only disadvantage it has is it
only takes 8 characters of string. But I took care by appending the
next 8 char encoded part after the 1st part and could manage to handle
long strings.

This is just for folks who also get stuck. :-)

Thanks Everybody,
zix
 
Joe Beanfish...
Posted: Tue Sep 08, 2009 10:53 am
Guest
zix wrote:
Quote:
On Sep 6, 2:23 pm, Markku Kolkka <markku.kol... at (no spam) iki.fi> wrote:
zix wrote:
I am trying to use the encrypt API in linux.
(...)
I expected an ecrypted string, but I am gettign the output as:
str mod is errno is 0
where am i going wrong? any idea?
encrypt() works on 64-bit blocks of data encoded in an array of 64
bytes, it doesn't handle C-style null terminated text strings. Read the
man page for encrypt().

--
Markku Kolkka
markku.kol... at (no spam) iki.fi

oops, thanks a lot..btw, how do i then encrypt/decrypt a string in
linux?

Pad the length with NULLs to the required length.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sat Nov 28, 2009 11:08 am