PDA

View Full Version : C++ && md5sum's



JNowka
December 31st, 2006, 11:51 PM
I am wondering if there are any header files for C++ to deal with md5 sums. I have not worked with md5 sums before, and am unsure how to go about this. I just want to convert a password into a md5 sum for security reasons. I don't want to do this using a file, because I am unsure if this will change the md5sum, so using md5sum that comes with Ubuntu is possibly useless. Any help will be much appreciated.

Thank you.

duff
January 1st, 2007, 05:32 AM
ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/packages/md5.tar.gz

amo-ej1
January 2nd, 2007, 07:54 AM
The easiest would be to steal (did i say steal ? i meant borrow ;-) ) some code from passwd:


apt-get source passwd

Which contains this function:



char *pw_encrypt (const char *clear, const char *salt)
{
static char cipher[128];
char *cp;

cp = crypt (clear, salt);
if (!cp) {
/*
* Single Unix Spec: crypt() may return a null pointer,
* and set errno to indicate an error. The caller doesn't
* expect us to return NULL, so...
*/
perror ("crypt");
exit (1);
}
if (strlen (cp) != 13)
return cp; /* nonstandard crypt() in libc, better bail out */
strcpy (cipher, cp);

return cipher;
}


This relies on man 3 crypt from the libc6 package (so a basic library readily available, remember to link with -lcrypt).

amo-ej1
January 2nd, 2007, 07:56 AM
Oh yeah, and in the same manpage, all the way down:



The glibc2 version of this function has the following additional fea‐
tures. If salt is a character string starting with the three charac‐
ters "$1$" followed by at most eight characters, and optionally termi‐
nated by "$", then instead of using the DES machine, the glibc crypt
function uses an MD5-based algorithm, and outputs up to 34 bytes,
namely "$1$<string>$", where "<string>" stands for the up to 8 charac‐
ters following "$1$" in the salt, followed by 22 bytes chosen from the
set [azAZ09./]. The entire key is significant here (instead of only
the first 8 bytes).

tasos
January 6th, 2008, 02:16 PM
man 3 crypt does not return the man page..
is there an extra package libc6-doc or something?
thanx

wolfbone
January 6th, 2008, 02:47 PM
Primary documentation for glibc is in texinfo format, not man pages.

geirha
January 6th, 2008, 05:24 PM
Install the manpages-dev package. At least the man-page for crypt is there

tasos
January 6th, 2008, 06:40 PM
Thanx geirha..that did the trick ;)