Delphi Hash算法[2] MD5
{该文首发于博客园 滔Roy,无须授权即可转发,请自觉保留头部申明}
Delphi Hash算法[2] MD5
引用单元:IdHashMessageDigest,IdHash;
1、字符串。输出MD 32位:
var
md5:TIdHashMessageDigest5;
dd:T4x4LongWordRecord;
begin
md5:=TIdHashMessageDigest5.Create;
dd:=md5.HashValue(Memo1.Text);
Memo2.Text:=md5.AsHex(dd); //默认是32位长度字符
md5.Free;
end;
2、字符串。输出MD 16位
var
md5:TIdHashMessageDigest5;
dd:T4x4LongWordRecord;
begin
md5:=TIdHashMessageDigest5.Create;
dd:=md5.HashValue(Memo1.Text);
Memo2.Text:= Copy(md5.AsHex(dd),9,16);
md5.Free;
end;
3、文件
var
md5:TIdHashMessageDigest5;
dd:T4x4LongWordRecord;
sFileStream:TFileStream;
begin
try
md5:=TIdHashMessageDigest5.Create;
if OpenDialog1.Execute then begin
sFileStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead or fmShareExclusive); //文件流
dd:=md5.HashValue(sFileStream);
Memo2.Text:= md5.AsHex(dd); //默认是32位长度字符
sFileStream.Free;
end;
finally
md5.Free;
end;
end;
创建时间:2021.04.29 更新时间:
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!