本文整理自网络,侵删。
Delphi XE8和更高版本具有在System.Hash单元中生成哈希值的功能。
System.Hash.THashMD5 实现MD5哈希的记录。System.Hash.THashSHA1 实现SHA-1哈希的记录。
System.Hash.THashBobJenkins 实现Jenkins哈希的记录。
以下代码是使用THashMD5的示例。
md5
uses System.Hash;
procedure TForm1.Button1Click(Sender: TObject);const MSG = 'Hello, world';var MD5: THashMD5; Hash: string;begin MD5 := THashMD5.Create; MD5.Update(MSG); Hash := MD5.HashAsString;
Edit1.Text := Hash;end;您还可以从字节字符串生成哈希值。
procedure TForm1.Button2Click(Sender: TObject);const MSG = 'Hello, world';var MD5: THashMD5; Bytes: TBytes; Hash: string;begin MD5 := THashMD5.Create; Bytes := TEncoding.UTF8.GetBytes(MSG); MD5.Update(Bytes, Length(Bytes)); Hash := MD5.HashAsString;
Edit2.Text := Hash;end;
相关阅读 >>
Delphi使用idtcpclient和idtcpserver相互发送数据
更多相关阅读请进入《Delphi》频道 >>