MD5 Message Digest Unit

   
Release: 1.1.1
Date: 11 January 2014
Delphi Compatibility:
D1 D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 DXE3 DXE4
Red LED Red LED Red LED Red LED Red LED Red LED Red LED Red LED Red LED Red LED Green LED Green LED Green LED Green LED Green LED Green LED

About the Unit

Introduction

This unit contains an implementation of the MD5 message digest algorithm. A Delphi class named TPJMD5 provides overloaded methods for calculating the MD5 of

  • Files.
  • Byte arrays.
  • Strings: Unicode, ANSI and short strings are all supported.
  • Streams.
  • Untyped data buffers (useful for getting the MD5 of ordinal values).

Data types can be mixed and matched. Class methods provide quick shortcuts to taking the MD5 of a single file or single data item without having to create and free a TPJMD5 instance.

There is also an "advanced" record, TPJMD5Digest, that encapsulutes a MD5 digest. Operator overloads for assigning digests to and from strings and bytes arrays are provided. The digest can also be read in long words chunks.

The code was developed from scratch based on the algorithm presented in RFC 1321. Portions of the code are translated from the reference C code supplied in the RFC. However the code is not a literal translation into Pascal from the reference C code.

The algorithm and reference code are copyright © 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.

Compatibility

As of v1.1 the unit is compatible with both the 32 bit and 64 bit Delphi Windows compilers. It has not been tested with the OSX compiler.

The code can be used in applications using either the VCL or FireMonkey 2 framework.

Documentation

The component is documented online. This documentation includes a "How-To" Guide containing a wide selection of demo code.

There is no help file.

Testing

DUnit tests for the unit are supplied in the download. The tests include all those specified in RFC 1321.

Feedback & Queries

If you find any bugs or want to suggest a new feature please report them using the Issue Tracker.

Click the Create Ticket button to create a ticket then complete the form giving as much information as possible. Please note: this issue tracker is shared among all the projects in the DelphiDabbler Code Library, so please make sure you enter md5 in the Project edit box. You should also choose Defect in the Type drop down list to report a bug or Enhancement to request a new feature.

If you have created a bug fix or have implemented a new feature please attach a zip file to your ticket that contains your source code.

Should you have any queries about using the components please read the documentation.

If you can't find an answer in the documentation then post a message in the discussion group.

Please do not email me or use the contact page to report bugs, ask for new features or to find out how to use the unit.
I'm afraid I have very limited time available to support the code library, and can't guarantee I'll find time for personalised advice.

Rationale

So why write this code?

Well, I'd been searching for an up-to-date implementation of the MD5 algorithm that meets these criteria:

  1. No dependency on .obj files or DLLs. I want pure Pascal code.
  2. Open source with a license compatible with the Mozilla Public License because I want to use it in an MPLd application of mine, so GPL-only code is ruled out.
  3. Compiles and works with the Unicode Delphi Compilers.
  4. Object oriented.
  5. Easy to get an MD5 digest from all sorts of data without messing about converting it and playing around with contexts etc.

I couldn't find anything that suited, so it seemed easier to start again. After a couple of false starts, this unit is the result.