Unix Programming - Creating an MD5 hash

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2004 > Creating an MD5 hash





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Creating an MD5 hash
Carsten Maul

2004-09-23, 5:54 pm

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

Casper H.S. Dik

2004-09-23, 5:54 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.
James Antill

2004-09-24, 5:51 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/

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com