Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

MD5 How-to: How To Get Started

Applies to: ~>1.0

This is the “hello world” how-to where you’ll learn just enough to generate your first MD5 digest.

We’ll get the MD5 digest of the contents of the string Hello world. Here’s the code:

var
  Digest: TPJMD5Digest;
begin
  Digest := TPJMD5.Calculate('Hello world');
  ShowMessage(Digest);
end;

This code gets the MD5 hash of “Hello World” and displays its text representation in a message box.

The TPJMD5.Calculate method creates the MD5 hash (or digest) and stores it in the Digest variable, which is a record of type TPJMD5Digest.

There are several overloaded versions of TPJMD5.Calculate and the one used here is one of the Unicode string overloads. This one converts the string to its default ANSI encoding then takes the hash of that.

TPJMD5Digest is also a little magical in that it automatically generates the string representation of itself when assigned to a string or when it is used in a string context. Since ShowMessage takes a string parameter Digest converts itself into its string representation, which is displayed in the dialog box.

See Also