I am using that function on Delphi XE2 to hash a string.
I have a bad result if the program is run on Windows 10 — the result is null
because TidHashSHA512.isavailable
is FALSE
.
What do I have to do?
function HashSHA512String(Text: String): String;
var
IdHashSHA512: TIdHashSHA512;
begin
Result := '';
if HashFunctionsOpenSSLLoaded then begin
if TIdHashSHA512.IsAvailable then begin // <-- ADD THIS
IdHashSHA512 := TIdHashSHA512.Create;
try
Result := IdHashSHA512.HashStringAsHex(Text);
finally
FreeAndNil(IdHashSHA512);
end;
end;
end;
end;
Most of Indy's SHA hashes depend on your app hooking up an external hashing library to Indy. Only SHA-1 (amongst a few other non-SHA hashes) is currently implemented natively.
To enable SHA-512, the following callback function pointers in the
IdFIPS
unit must be assigned at runtime:IsHashingIntfAvail
UpdateHashInst
FinalHashInst
IsSHA512HashIntfAvail
GetSHA512HashInst
You can use any hashing library you want, as long as the above function pointers are assigned to suitable functions.
Indy provides an implementation that uses hashing functions from OpenSSL. To use it, you can either:
add the
IdSSLOpenSSLHeaders
unit to youruses
clause, and then call itsLoad()
function at runtime.add the
IdSSLOpenSSL
unit to youruses
clause, and then call itsLoadOpenSSLLibrary()
function at runtime.Either way, you will have to distribute the two OpenSSL DLLs with your app (libeay32.dll and ssleay32.dll, which you can download from Indy's Fulgan mirror). Be sure to use builds that have been compiled with SHA-512 enabled.