Hola, conseguí este código que supuestamente hace un Sha256 HMAC en delphi, pero para testearlo y ver si me sirve, necesito que funcione y no logro hacerlofuncionar.
Les dejo el dódigo y yo tengo Delphi XE7 y ahí me daerror en incompatibilidad con los TidBytes y los TArray.
Código Delphi
[-]unit HMAC;
interface
uses
System.SysUtils,
EncdDecd,
IdHMAC,
IdSSLOpenSSL,
IdHash;
type
THMACUtils < T: TIdHMAC, constructor> = class
public
class function HMAC(aKey, aMessage: RawByteString): TBytes;
class function HMAC_HexStr(aKey, aMessage: RawByteString): RawByteString;
class function HMAC_Base64(aKey, aMessage: RawByteString): RawByteString;
end;
implementation
class function THMACUtils.HMAC(aKey, aMessage: RawByteString): TBytes;
var
_HMAC: T;
begin
if not IdSSLOpenSSL.LoadOpenSSLLibrary then Exit;
_HMAC:= T.Create;
try
_HMAC.Key := BytesOf(aKey); <----------------------------- Acá ya empieza a dar error y no encuentro un convertidor para eso.
Result:= _HMAC.HashValue(BytesOf(aMessage));
finally
_HMAC.Free;
end;
end;
class function THMACUtils.HMAC_HexStr(aKey, aMessage: RawByteString): RawByteString;
var
I: Byte;
begin
Result:= '0x';
for I in HMAC(aKey, aMessage) do
Result:= Result + IntToHex(I, 2);
end;
class function THMACUtils.HMAC_Base64(aKey, aMessage: RawByteString): RawByteString;
var
_HMAC: TBytes;
begin
_HMAC:= HMAC(aKey, aMessage);
Result:= EncodeBase64(_HMAC, Length(_HMAC));
end;
end.