新旧版Indy的TIdHashMessageDigest5类计算MD5的区别
uses IdHashMessageDigest,IdHash;
{$R *.dfm}
//新版XE2中的写法 ,一句就可搞定 可以直接HashStringAsHex
function MD5(const S: string): string;
var
MyMD5: TIdHashMessageDigest5;
begin
MyMD5 := TIdHashMessageDigest5.Create;
try
Result := MyMD5.HashStringAsHex(S);
finally
MyMD5.Free;
end;
end;
//已知10.2.0以下indy版本的写法
function MD52(const S: string): string;
var
MyMD5: TIdHashMessageDigest5;
Digest:T4x4LongWordRecord;
begin
MyMD5 := TIdHashMessageDigest5.Create;
try
Digest := MyMD5.HashValue(S);
Result:=MyMD5.AsHex(Digest);
finally
MyMD5.Free;
end;
end;
Result := Md5Encode.AsHex(Md5Encode.HashValue(S)); // Indy10.1.5以下的写法
Result : = Md5Encode.HashStringAsHex(S); // Indy10.2+中可以直接HashStringAsHex
本文来自博客园,作者:IT情深,转载请注明原文链接:https://www.cnblogs.com/wh445306/p/16751701.html