Skip over navigation

Welcome to the all new DelphiDabbler website.

I hope you like it.

There are going to be bugs. Please report any you find on the website's issues page (GitHub account required). Thanks.

Click the close button and you won't see this message again.

MD5 Message Digest Unit

Implements the MD5 Message Digest Algorithm

Version 1.1.1
Released 11 Jan 2014
Platforms Win32 & Win64
Framework RTL
Compatibilty Delphi 2009 & later

Overview

This unit contains an object-oriented 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 explicitly 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 byte 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.

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

So why write this code?

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

  1. No dependency on .obj files or DLLs. I wanted 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 was 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 from scratch. After a couple of false starts, this unit is the result.

Get The Code

You can download the latest version of the MD5 Message Digest Unit directly from SourceForge as dd-md5-1.1.1.zip.

Download v1.1.1

MD5 Message Digest Unit is a sub-project of the DDabLib project which is maintained in a Subversion repository. The code is developed in the trunk/projects/md5 branch.

Subversion users can check out the source code of the current release from the repository on SourceForge by doing:

svn checkout http://svn.code.sf.net/p/ddablib/code/tags/projects/md5/release-1.1.1 codedir

where codedir is the directory where you want to checkout code. To check out other versions, simply specify a different version number.

The latest development tree can be checked out using:

 svn checkout http://svn.code.sf.net/p/ddablib/code/trunk/projects/md5 codedir

Check outs are read only, but you can easily contribute code: see Feedback & Queries below.

Installation

The MD5 Message Digest Unit, documentation and test suite are supplied in a zip file. Before installing you need to extract all the files, preserving the directory structure. The following files will be extracted:

  • PJMD5.pas – source code.
  • ReadMe.htm – read-me file.
  • ChangeLog.txt – project change log.
  • Documentation.URL – short-cut to the unit's online documentation.
  • License.txt – the project's license.
  • MPL-2.txt – the Mozilla Public License v2.0.
  • MD5-Notice.txt – MD5 algorithm licensing notice.

In addition to the above files you will find the DUnit tests for PJMD5.pas in the Test sub-directory.

There are three possible ways to use the unit.

  1. The simplest way is to add PJMD5.pas to your projects as you need it.
  2. To make the unit easier to re-use you can either copy it to a folder on your Delphi search path, or add the folder where you extracted the unit to the Delphi Search path. You then simply use the unit as required without needing to add it to your project.
  3. For maximum portability you can add the unit to a Delphi 32 bit or 64 bit Windows package. If you need help doing this see here.

Documentation

The MD5 Message Digest Unit is comprehensively documented online here

The project's change log can be viewed on SourceForge

A read-me file (ReadMe.htm) is included in the project download.

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.

The 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 to make it clear which project you are referring to. 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 unit please read the documentation. If you can't find an answer in the documentation then post a message in the discussion group.

License

The MD5 Message Digest Unit is open source. It is copyright © 2010-2014 by Peter Johnson. The source code is made available under the terms of the Mozilla Public License v2.0. All relevant trademarks are acknowledged.