1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| uses
IdGlobal, IdHashSHA, IdHMAC, IdHMACSHA1, IdSSLOpenSSL;
function TForm2.CalculateHMACSHA512(const value, salt: String): String;
var
// hmac: TIdHMACSHA256;
hmac: TIdHMACSHA512;
hash: TIdBytes;
begin
LoadOpenSSLLibrary;
if not TIdHashSHA512.IsAvailable then
raise Exception.Create('SHA512 hashing is not available!');
// hmac := TIdHMACSHA224.Create;
// hmac := TIdHMACSHA256.Create; //varchar64
// hmac := TIdHMACSHA384.Create;
hmac := TIdHMACSHA512.Create; //varchar128
try
hmac.Key := IndyTextEncoding_UTF8.GetBytes(salt);
hash := hmac.HashValue(IndyTextEncoding_UTF8.GetBytes(value));
Result := ToHex(hash);
finally
hmac.Free;
end;
end; |
Partager