Calculating HMAC hash in Android using Delphi 10 [on hold]

  

i’m using external DLL in VCL apps to calculate the HMAC sha256 hash,https://www.chilkatsoft.com/delphiDll.asp ,i need a way to do it for Android in Delphi 10, i couldn’t find any that works for android in delphi,
this the code to do it using DLL

function TForm2.HMAC(const s: pwidechar): string;
var
crypt: HCkCrypt2;
success: Boolean;
mac: PWideChar;

begin
crypt := CkCrypt2_Create();

// Any string argument automatically begins the 30-day trial.
success := CkCrypt2_UnlockComponent(crypt,’Anything for 30-day trial.’);
if (success <> True) then
begin
Exit;
end;

// The output will be Hex, so set the EncodingMode:
CkCrypt2_putEncodingMode(crypt,’hex’);

// Set the hash algorithm:
// Choices are: md5, sha-1, sha256, sha384, sha512, md2, haval
CkCrypt2_putHashAlgorithm(crypt,’sha256′);

// Set the HMAC key:
CkCrypt2_SetHmacKeyEncoded(crypt,’my key’,’ascii’);
mac := CkCrypt2__hmacStringENC(crypt,s);
Result := (mac);

CkCrypt2_Dispose(crypt);

end;

UPDATE

i’ve found a piece of code to get the HMAC SHA256..but i couldn’t understand
how it works, like the above code ?

var
Hash: TIdHMACSHA256 ;
HashValue: TBytes;
begin
SetCurrentDir(ExtractFilePath(ParamStr(0)));
Hash := TIdHMACSHA256 .Create;
try
Hash.Key := TEncoding.ASCII.GetBytes(‘devaee2’);
HashValue := Hash.HashValue(TFile.ReadAllBytes(‘menu.xml’));
// HashValue is an empty array, why?
Tag := Length(HashValue);
TFile.WriteAllBytes(‘menu.xml.hash’, HashValue);

finally
FreeAndNil(Hash);
end;
end;

Comments are closed.