Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TIdHMACSHA256.TIdHMACSHA384.TIdHMACSHA512 do not work in Delphi

Tags:

delphi

indy

Why HashValue function of TIdHMACSHA256+ (Indy/delphi) always return empty? For example, the code below does not work.

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;
like image 520
MajidTaheri Avatar asked Dec 21 '22 12:12

MajidTaheri


1 Answers

The problem is that you have not successfully loaded the OpenSSL libraries that are needed to implement the hash. Call IdSSLOpenSSL.LoadOpenSSLLibrary. You'll also need to make sure that your program can find suitable OpenSSL DLLs.

like image 55
David Heffernan Avatar answered Dec 24 '22 02:12

David Heffernan