Creating an MD5 hash

  • Follow


Hi,


I want to generate an MD5 checksum with crypt.h, installed OS Debian Woody.
Unfortunately I only get DES hashes with

strncpy(salt, row[0], 12);
salt[12] = '\0';
encryptedPass = crypt(passwd, salt);
free(salt);

Later I compare the two:

if (!strcmp(row[0], encryptedPass))

row[0] looks like that: $1$mYV0L3j8$nUUWy09JYrzdXurr92ywv1

salt starts with $1$ to indicate that I want an MD5 hash.

Unfortunately the encryptedPass looks like that:
1ba49f4d1ff0f49c

What am I doing wrong ? Did I forget anything ?

Thanks

0
Reply carsten_maul (2) 9/23/2004 2:40:56 PM

Carsten Maul <carsten_maul@gmx.de> writes:

>I want to generate an MD5 checksum with crypt.h, installed OS Debian Woody.
>Unfortunately I only get DES hashes with

>strncpy(salt, row[0], 12);
>salt[12] = '\0';
>encryptedPass = crypt(passwd, salt);
>free(salt);

Typical use is:

	crypt(passwd, row[0]);

i.e., pass the entire encrypted password in as salt.

That makes your code portable to different algorithms.

Casper
-- 
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
0
Reply Casper 9/23/2004 5:35:48 PM


On Thu, 23 Sep 2004 16:40:56 +0200, Carsten Maul wrote:

> Hi,
> 
> 
> I want to generate an MD5 checksum with crypt.h, installed OS Debian Woody.
> Unfortunately I only get DES hashes with
> 
> strncpy(salt, row[0], 12);
> salt[12] = '\0';

> row[0] looks like that: $1$mYV0L3j8$nUUWy09JYrzdXurr92ywv1
> 
> salt starts with $1$ to indicate that I want an MD5 hash.

 You need at least "$1$mYV0L3j8$" which is bigger than 11 characters. And
as casper said, the second argument should be const char * ... so you
don't need the copy.

-- 
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/

0
Reply James 9/24/2004 5:56:10 PM

2 Replies
445 Views

(page loaded in 0.044 seconds)

Similiar Articles:













7/22/2012 10:54:11 AM


Reply: