MD5 and Cocoa

Posted on September 4, 2004
Filed Under /dev/null/ | 61 views |

I must admit: I was pretty surprised to learn that the Cocoa API doesn’t contain a built-in MD5 hash class, it seems to contain damned near everything else under the sun.

Some Googling indicated that you simply just add libcrypto to your project and include openssl/evp.h. From there Bob’s yer uncle, obviously.

Except that I have no idea what they’re talking about so instead I think I’ll use Pretzel’s “silly” Objective-C class instead: cocoa md5. Thanks dude!

Update: This just in from the author of MD5Hasher:

thanks! but I don’t recommend anybody use my md5 hasher class — i forgot to do memory management (!!!), written in a weird style etc.

i’d recommend using libcrypto (add /usr/lib/libcrypto.dylib to your project and target(s)) instead:


#include <openssl/md5.h>

MD5_CTX ctx;
char out[16];

MD5_Init(&ctx);
MD5_Update(&ctx, yourstring, length_of_yourstring);
MD5_Final(out, &ctx);

Comments

Comments are closed.