Hi,
is it possible to get an SHA Hash String from a local file with SB ?
Like "idmd5.HashStreamAsHex(fs)" with indy.
Regards
SHA Hash from local File
Re: SHA Hash from local File
To solve the issue you can use the next code:
Note that to run this code, you should add the ScUtils, ScHash units to the USES clause of your module.
Code: Select all
const
BUFFER_SIZE = 64 * 1024;
var
Stream: TStream;
Count: Int64;
SHA: THash_SHA1;
TmpBuf: TBytes;
BufCount: integer;
Buf: TBytes;
Hash: string;
...
SHA := THash_SHA1.Create;
try
Stream.Position := 0;
Count := Stream.Size;
SetLength(TmpBuf, BUFFER_SIZE);
while Count > 0 do begin
if Count > BUFFER_SIZE then
BufCount := BUFFER_SIZE
else
BufCount := Count;
Stream.ReadBuffer(TmpBuf[0], BufCount);
SHA.TransformBlock(TmpBuf, 0, BufCount);
Dec(Count, BufCount);
end;
SHA.TransformFinalBlock(nil, 0, 0);
Buf := SHA.Hash;
Hash := BytesToHexStr(Buf);
finally
SHA.Free;
end;
Re: SHA Hash from local File
Great, many thanks.
And it is realy fast!
And it is realy fast!
Re: SHA Hash from local File
Thank you for interest to our product.
Feel free to contact us if you have any further questions about our products.
Feel free to contact us if you have any further questions about our products.