[英]Delphi calculate TStream hash/checksum
i'm looking for a fast way for calculate a checksum of TStream (TMemoryStream). 我正在寻找一种计算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? 有一种快速的方法来计算流校验和吗?
This code calculates MD5 - it is cryptographic hash, rather complex and slow. 此代码计算MD5-这是加密哈希,相当复杂且缓慢。
For checksum you can try simpler algorithms like BobJenkinsHash
(S ystem.Hash.THashBobJenkins.GetHashValue ). 对于校验和,您可以尝试使用更简单的算法,例如
BobJenkinsHash
(S ystem.Hash.THashBobJenkins.GetHashValue )。
Also you can check performance of Spring4d and DCPCrypt implementations of MD5 您还可以检查MD5的Spring4d和DCPCrypt实现的性能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.