A
Abby
the sources of the openssl crypto library contain a nice md5 implementation in C.
And other crypto oder hash algorithms as well.
http://www.openssl.org/source/
I use the following code, but it doesn't work.
#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
int main(){
char password[20] = "password";
MD5_CTX context;
int i;
unsigned char digest[16];
unsigned int len = strlen (password);
MD5_Init(&context);
MD5_Update (&context, password, len);
MD5_Final(digest, &context);
printf ("MD5(\"%s\") = ", password);
for (i = 0; i < 16; i++) {
printf ("%02x", digest);
}
printf ("\n");
return 0;
}
When I compiled this code, it generate error said
[Linker error] undefined reference to `_MD5_Init'
[Linker error] undefined reference to `_MD5_Update'
[Linker error] undefined reference to `_MD5_Final'
I'm not sure if I'm doing the right way. Please recommend.