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.
- How-tos:
- Programmers' Guide:
- TPJMD5Digest
- TPJMD5.Calculate (Unicode overloads)