Implementing the MD5 Algorithm
According to the "Executive Summary" of RFC 1321,
"The MD5 algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA."
This algorithm was developed by Professor Ronald L. Rivest of MIT and can be found presented in several languages. What I provide to you here is a C++ derivative of the original C implementation of Professor Rivets.
The library code itself is platform-independant and has been tested in Redhat Linux. I've included the sample code and makefile that I used for the Linux test. The demo, however, was written with Visual C++ 6 on a Windows 2000 platform.
The screenshot here is of the MFC demo projects that I've included to show how to make use of the library calls. With this, you can genereate MD5 fingerprints of text phrases or files.

The library is well insulated and provides wrapper functions to make it as easy to use as this:
CString csString = MD5String("Some string you want to generate an
MD5 key for.");
Downloads
Download demo project - 127 KbDownload source - 7 Kb

Comments
Other algorithm
Posted by sedi on 02/15/2009 11:39pmDemo error
Posted by phoenixatlantios on 06/24/2006 05:54amYou'll need to change the: #include "md5.h" to #include "md5.cpp" For the test file to compile properly, other than that it's awesome - exactly what I was looking for :)
Replythank you!
Posted by Legacy on 12/16/2003 12:00amOriginally posted by: Dmitry Seliverstov
*
Reply
other solution method about memory leak
Posted by Legacy on 11/26/2003 12:00amOriginally posted by: chenxinyi
every invoke MD5String function that it will return a pointer, you can do:
delete pointer;
-
Replym-leaks
Posted by MAxZ on 07/15/2005 07:56amchar* PrintMD5(uchar md5Digest[16]) { char chBuffer[256]; char chEach[10]; int nCount; memset(chBuffer,0,256); memset(chEach, 0, 10); for (nCount = 0; nCount < 16; nCount++) { sprintf(chEach, "%02x", md5Digest[nCount]); strncat(chBuffer, chEach, sizeof(chEach)); } return strdup(chBuffer);// this memory need to be returned }ReplyVery easy to use, thanks
Posted by Legacy on 05/15/2003 12:00amOriginally posted by: KP
I like it
Reply
Not be thread securite!
Posted by Legacy on 05/03/2003 12:00amOriginally posted by: Zhiwei Li
Don't use static in function, because it is not thread security.
So, you should use TLS instead!
ReplyMore correct memory leak solution
Posted by Legacy on 09/10/2002 12:00amOriginally posted by: M A V
Replyavoid Memory Leak
Posted by Legacy on 09/09/2002 12:00amOriginally posted by: Solomon Wu
ReplyMemory Leak?
Posted by Legacy on 09/01/2002 12:00amOriginally posted by: HenryVIII
Running your demo program in debug and memory leaks were detected.
ReplyWhat about Endian?
Posted by Legacy on 08/15/2002 12:00amOriginally posted by: Anthony Mai
You claim your code is platform independent. But your code does not take into consideration of whether the system is big endian or little endian. It can't work on both systems since it does not take care of endianness.
Also within your source code you need to provide a known string and known output so one can verify that the algorithm produces expected output, instead of trash.
Reply