RSA MD5 Message Digest


This article was contributed by Nick Stone of Langfine Ltd.

Overview

This is a C++ implementation of the RSA MD5 message digest algorithm. The algorithm calculates a 16 byte checksum for any data sequence (e.g., array of bytes, a string or a file). Full details of the MD5 algorithm are provided within the code.

Two projects are provided:

  • MD5.dsw—builds a library that provides the MD5 calculation routines.
  • MD5ChecksumTest.dsw—builds a modeless dialog test environment that demonstrates use of the MD5 library and provides a simple verification tool.

Important Notes

Wherever this implementation of the RSA MD5 algorithm is used, the RSA copyright notices etc. must be adhered to, as described within the code and the test application’s “About” box.

All use of this algorithm is at the users risk—no liability of any kind whatsoever is accepted by Nick Stone nor Langfine Ltd.

Further Details

The MD5 message digest algorithm is wrapped in a C++ class named CMD5Checksum.

Three public functions are exported:

CString GetMD5(BYTE* pBuf, UINT nLength);
CString GetMD5(CFile& File);
CString GetMD5(const CString& strFilePath);

All are implemented as static functions. The checksum calculated is returned as a 32 character hexadecimal number held in a CString. GetMD5 is overloaded to take data to be checksummed as either an array of bytes or a file.

The class CMD5Checksum is held within the MD5.dsw project. Building this project
creates MD5.lib.

A test environment is provided in the project MD5ChecksumTest.dsw. This allows the user to type a string and see its checksum calculated in real time and also to select a file for checksum. Data files are provided containing simple test data; get the checksum for these and then try typing the file’s contents into the first edit box and compare the two checksums thus obtained (they should be the same!) The test environment also includes a “Self Test” button. This checksums each of the supplied test data files in turn and checks the calculated checksum with the known correct value.

Downloads


Download source – 18 Kb

Download demo project – 46 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read