Md5?

btoth

Person that uses a Mac
Is there a simple function available to return the md5 hash of a string and key? After searching through the Apple Docs and then on the Internet all night I finally found that OS X does have an md5 command and openssl installed already. However, is there a C header file or Apple function call that can return a value rather than having to mess with NSTask and NSPipe to get a value?
 
Ok, so after hunting around on my hard drive (because the Finder's search box won't search the hidden Unix files for some reason) I found OpenSSL/md5.h which I assume does what I want it to do... well there's no documentation of course, so does someone know how to use it? :D
 
There's documentation, all right. You have to use 'man 3 md5'. The 3 indicates that you're interested in C function calls instead of shell commands. The docs for MD5() are pretty straightforward:
Code:
unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);

MD2(), MD4(), and MD5() compute the MD2, MD4, and MD5 message digest of
the n bytes at d and place it in md (which must have space for
MD2_DIGEST_LENGTH == MD4_DIGEST_LENGTH == MD5_DIGEST_LENGTH == 16 bytes
of output). If md is NULL, the digest is placed in a static array.

There are piles of other routines in there with _Init, _Update, _Final....I'd guess these are for hashing data as it comes off a network stream instead of waiting and doing it all at once...but you probably don't need that quite yet. The docs also mention you should use SHA1 (man 3 sha1) if you're not trying to be compatible with someone else, since it's a more advanced algorithm.
 
Back
Top