Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
MD5 Hash a String (such as a password string)
See more Encryption Examples
Demonstrates how to MD5 hash a string to get MD5 hash in hex encoded string representation. (The MD5 hash is 16 bytes, and therefore a hex encoded MD5 hash would be 32 chars.)Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Crypt2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
password: string;
crypt: TCrypt2;
md5Hex: string;
begin
password := 'myPassword';
crypt := TCrypt2.Create;
crypt.HashAlgorithm := 'md5';
crypt.EncodingMode := 'hex';
md5Hex := crypt.HashStringENC(password);
WriteLn('MD5 hash (as a hex string) = ' + md5Hex);
// The hex string will be uppercase. Your application
// can easily convert it to lowercase if desired via non-Chilkat means..
crypt.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.