Delphi IdHashMessageDigest MD5用法


本文整理自网络,侵删。

 
uses IdHashMessageDigest;

procedure TForm1.Button1Click(Sender: TObject);
var
  md5: TIdHashMessageDigest5;
  msg: String;
  hash: String;
begin
  msg := 'Hello, world';
  md5 := TIdHashMessageDigest5.Create;
  hash := LowerCase(md5.HashBytesAsHex(TEncoding.ASCII.GetBytes(msg)));
  md5.Free;

  ShowMessage(hash); //=> bc6e6f16b8a077ef5fbc8d59d0b931b9
end;
另一种方法是将字符串和编码传递给TIdHashMessageDigest5的HashStringAsHex方法。

md5.HashStringAsHex(msg, TEncoding.ASCII)
例子

procedure TForm1.Button2Click(Sender: TObject);
var
  md5: TIdHashMessageDigest5;
  msg: String;
  hash: String;
begin
  msg := 'Hello, world';
  md5 := TIdHashMessageDigest5.Create;
  hash := LowerCase(md5.HashStringAsHex(msg, TEncoding.ASCII));
  md5.Free;

  ShowMessage(hash); //=> bc6e6f16b8a077ef5fbc8d59d0b931b9
end;

相关阅读 >>

Delphi webbrowser1实现滚屏

Delphi源码webbrowser多次执行documentcomplete

Delphi 通过递归来实现搜索文件

Delphi 数据库处理密码防止sql注入

Delphi指针的定义和取值

Delphi获取内存及cpu信息的函数

Delphi 限制tedit控件只能输入数字,小数点和负号

Delphi几个进制相关的代码(hextoint、hextoasc)

Delphi listview 导出excel txt vcf 单元

Delphi removedir 删除文件夹

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...