How do I hash a string with Delphi?

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.

Leave a Comment