ar099968
ar099968

Reputation: 7547

Delphi calculate TStream hash/checksum

i'm looking for a fast way for calculate a checksum of TStream (TMemoryStream). The purpose is store the hash and use it for detect if the checksum is changenged after some operation.

this is my code:

function GetChecksum(const Stream: TStream): String;
var 
  MD5: TIdHashMessageDigest5;
begin
  MD5 := TIdHashMessageDigest5.Create;
  try
      Result := MD5.HashStreamAsHex(Stream);
  finally
      MD5.Free;
  end;
end;

it works, but with a huge stream is a bit slow.

There is a fast way for calculate a stream checksum?

Upvotes: 2

Views: 1577

Answers (1)

MBo
MBo

Reputation: 80197

This code calculates MD5 - it is cryptographic hash, rather complex and slow.

For checksum you can try simpler algorithms like BobJenkinsHash (System.Hash.THashBobJenkins.GetHashValue).

Also you can check performance of Spring4d and DCPCrypt implementations of MD5

Upvotes: 2

Related Questions