How do I hash a string with Delphi?

devstopfix picture devstopfix · Sep 12, 2008 · Viewed 79k times · Source

How do I make an MD5 hash of a string with Delphi?

Answer

devstopfix picture devstopfix · Sep 12, 2008

If you want an MD5 digest and have the Indy components installed, you can do this:

uses SysUtils, IdGlobal, IdHash, IdHashMessageDigest;

with TIdHashMessageDigest5.Create do
try
    Result := TIdHash128.AsHex(HashValue('Hello, world'));
finally
    Free;
end;

Most popular algorithms are supported in the Delphi Cryptography Package:

  • Haval
  • MD4, MD5
  • RipeMD-128, RipeMD-160
  • SHA-1, SHA-256, SHA-384, SHA-512,
  • Tiger

Update DCPCrypt is now maintained by Warren Postma and source can be found here.