I am trying to use the SHA-256 encryption function, but with no success.
I need to get a hash of a string and a file. I'm using Delphi 10.1 Berlin, and Indy for Hash.
My code:
uses System.Classes, IdHashSha, System.SysUtils;
function GetHashF(_filename: string): string;
var
sha: TIdHashSHA256;
fs: TFileStream;
begin
if TIdHashSHA256.IsAvailable then
begin
sha:= TIdHashSHA256.Create;
try
fs:= TFileStream.Create(_filename, fmOpenRead);
try
Result:= sha.HashStreamAsHex(fs);
finally
sha.Free;
end;
finally
fs.Free;
end;
end;
function GetHashS(_string: string): string;
var
sha: TIdHashSHA256;
begin
if TIdHashSHA256.IsAvailable then
begin
sha:= TIdHashSHA256.Create;
try
Result:= sha.HashStringAsHex(_string);
finally
sha.Free;
end;
end;
end;
But whenever I do this, it returns a clean string ("") for both function.
I used the breakpoint to check if it is passing from IsAvaible
, and it is not.
What is going on?