Implementing the MD5 Algorithm

Environment: Win32 & VC++ or Linux and gcc/egcs

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 Kb

Download source – 7 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read