HMAC-SHA256 in Delphi
Delphi ships with Indy installed, and Indy has a TIdHMACSHA256
class:
uses
IdGlobal, IdHashSHA, IdHMAC, IdHMACSHA1, IdSSLOpenSSL;
function CalculateHMACSHA256(const value, salt: String): String;
var
hmac: TIdHMACSHA256;
hash: TIdBytes;
begin
LoadOpenSSLLibrary;
if not TIdHashSHA256.IsAvailable then
raise Exception.Create('SHA256 hashing is not available!');
hmac := TIdHMACSHA256.Create;
try
hmac.Key := IndyTextEncoding_UTF8.GetBytes(salt);
hash := hmac.HashValue(IndyTextEncoding_UTF8.GetBytes(value));
Result := ToHex(hash);
finally
hmac.Free;
end;
end;
After a little more searching I found OpenStreamSec - which looks like it was abandoned a few years ago but still compiles in D2007.
http://sourceforge.net/projects/openstrsecii/
Generating a HMAC-256 for Amazon is really simple:
StrToMime64(HMACString(haSHA256, SecretKey, 32, DataToHash));