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
DCPCrypt
is now maintained by Warren Postma and source can be found here.
You can also use the WindowsCrypto API with Delphi:
There is a unit in there that wraps all the CryptoAPI. You can also use Lockbox, which is now open source.
In the end you can support pretty much any Hash algorithms with Delphi. The most common way is to use a library, like the Delphi Cryptography Package (D MylesCPypt). Another option is to use the Windows Cryptography API (through a wrapper unit). With all of these options using Delphi we can have many choices to hash a string.
If you want an MD5 hash string as hexadecimal and you have Delphi 25 installed, so you will have Indy 10.5.7 components and you can do this:
uses IdGlobal, IdHash, IdHashMessageDigest;
class function getMd5HashString(value: string): string;
var
hashMessageDigest5 : TIdHashMessageDigest5;
begin
hashMessageDigest5 := nil;
try
hashMessageDigest5 := TIdHashMessageDigest5.Create;
Result := IdGlobal.IndyLowerCase ( hashMessageDigest5.HashStringAsHex ( value ) );
finally
hashMessageDigest5.Free;
end;
end;
Also we can encrypt a string using SHA256 with the following code:
uses IdGlobal, IdHash, IdHashMessageDigest;
class function getSha256HashString(value: string): string;
var
hashMessageDigest5 : TIdHashMessageDigest5;
begin
hashMessageDigest5 := nil;
try
hashMessageDigest5 := TIdHashMessageDigest5.Create(IdMessageDigestSHA256);
Result := IdGlobal.IndyLowerCase ( hashMessageDigest5.HashStringAsHex ( value ) );
finally
hashMessageDigest5.Free;
end;
end;