This is not really a post… let see it more like a “memo” since every­time I have to imple­ment MD5 in some appli­ca­tion I always forget how to do…

First of all, we need the md5.c and md5.h files (note that the source in the link is an “appended” ver­sion of md5.h + md5.c, but if you look for them sin­go­larly on google you can find them already splitted).

Then we have to include the md5.h file in our source with an #include "md5.h".

Here there’s a code snip­pet of how to use it:

unsigned char *password = "hello, I'm a password!";
MD5_CTX ctx;
unsigned char password_hash[16];

MD5Init(&ctx);
MD5Update(&ctx, password, strlen((char *)password));
MD5Final(password_hash, &ctx);

We have to init the MD5 Con­text with MD5Init(), then update the MD5 with MD5Update() and saying to MD5 to store the result in password_hash by using MD5Final().

That’s all…