DelphiDabbler Wiki

MD5 Message Digest UnitTPJMD5 class

Project: MD5 Message Digest Unit

Unit: PJMD5.

Introduced: v1.0


This class implements the MD5 message digest algorithm. It produces a message digest (i.e. a 16 byte hash) from a sequence of octets (bytes).

TPJMD5 has been designed to make it easy to create MD5 hashes of different types of data. It does this by providing overloaded Process and Calculate methods that can each accept several different data types. See the Methods section below for details.

The MD5 hash is exposed as a record of type TPJMD5Digest that contains the hash in binary form. The record overloads various operators to make it easy to obtain a string representation of the hash and to access the hash itself either byte by byte or as a sequence of long words.


CreateObject constructor.
CalculateThere are numerous overloaded versions of Calculate for several different data types. These are class methods that create an MD5 hash directly from data passed to them. Each method returns the resulting hash as a TPJMD5Digest record.
CalculateFileThis class method is similar to the Calculate methods except that it calculates and returns the MD5 hash of the contents of a file.
ProcessEach of the numerous overloaded Process methods adds the data passed to it to the current MD5 hash. Process enables data to be added to the hash in chunks rather than all at once as is the case with Calculate. The methods also enable data of different types to be combined in the same hash.
ProcessFileThis method is similar to the Process method except that it adds the contents of a file to the current MD5 hash.
ResetResets the object and discards the current digest ready to calculate a new hash.
FinalizeFinalizes the current MD5 hash. Any attempt to add more data to the hash after calling this method raises an exception.


DigestRead only property that finalizes and provides access to the MD5 hash as a TPJMD5Digest record.
ReadBufferSizeProvides and sets the size buffer used when reading data from files and streams.
FinalizedRead only property that indicates if the MD5 hash has been finalized.


TPJMD5 exposes no events.

Class Constants

DefReadBufferSizeDefault buffer size used when reading streams and files.

See Also

Page last modified on June 21, 2011, at 02:59 PM