当前位置: 首页 > wzjs >正文

河南汉狮做网站的公司北京 酒店 企业 网站建设

河南汉狮做网站的公司,北京 酒店 企业 网站建设,十堰网站建设联系电话,泸州作网站建设联系电话1. 前言 今天做一个三方接口,接口文档描述签名采用MD5,但是实际测试过程中,始终校验不通过,经过和三方沟通,才知道采用的是HMAC-MD5。由于Delphi7没有对HMAC的支持,则采用XE版本来支持。本次使用Delphi XE …

1. 前言

        今天做一个三方接口,接口文档描述签名采用MD5,但是实际测试过程中,始终校验不通过,经过和三方沟通,才知道采用的是HMAC-MD5。由于Delphi7没有对HMAC的支持,则采用XE版本来支持。本次使用Delphi XE 10.3.3、Delphi 7来实现。

        HMAC 散列消息认证码 (Hash-based Message Authentication Code),它是一种基于加密哈希函数和共享密钥的消息认证协议。它是一种给消息加上数字签名的方法,这个签名是根据消息内容和一个共享密钥生成的,只有知道密钥的人才能生成或验证这个签名。
        HMAC - https://baike.baidu.com/item/hmac/7307543
        在线验证 https://www.btool.cn/hmac-generator

2. Delphi XE 10.3.3 实现动态库

2.1 工程文件 hmactool.dpr

library hmactool;{HMAC 散列消息认证码 (Hash-based Message Authentication Code)它是一种基于加密哈希函数和共享密钥的消息认证协议。它是一种给消息加上数字签名的方法,这个签名是根据消息内容和一个共享密钥生成的,只有知道密钥的人才能生成或验证这个签名。HMAC - https://baike.baidu.com/item/hmac/7307543在线验证 https://www.btool.cn/hmac-generator
}usesWinapi.Windows,System.SysUtils,System.Classes,InterfaceDll in 'InterfaceDll.pas';{$R *.res}exportsdll_hmac_md5,dll_hmac_sha1,dll_hmac_sha2;procedure DLLHandler(Reason: integer);
varbuf: array[0..1023] of char;
begincase Reason ofDLL_PROCESS_DETACH: //释放DLL时beginend;DLL_Process_Attach: //加载DLL时beginend;DLL_Thread_Attach: //主进程创建一个新线程时beginend;DLL_Thread_Detach: //主进程结束一个线程时beginend;end;
end;beginDLLProc := @DLLHandler;DLLHandler(DLL_Process_Attach);
end.

2.2 接口文件 InterfaceDll.pas

unit InterfaceDll;interfaceusesSystem.SysUtils, System.Hash;varErrInfo: WideString;function dll_hmac_md5(sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall;function dll_hmac_sha1(sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall;function dll_hmac_sha2(iType: Byte; sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall;implementationfunction dll_hmac_md5(sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall;
varKey, Data: WideString;Hash: THashMD5;HMAC: WideString;
beginData := Trim(sIn);Key:= Trim(sKey);Hash := THashMD5.Create;HMAC := Hash.GetHMAC(Data, Key);sOut:= PWideChar(HMAC);result:= 0;
end;function dll_hmac_sha1(sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall;
varKey, Data: WideString;Hash: THashSHA1;HMAC: WideString;
beginData := Trim(sIn);Key:= Trim(sKey);Hash := THashSHA1.Create;HMAC := Hash.GetHMAC(Data, Key);sOut:= PWideChar(HMAC);result:= 0;
end;function dll_hmac_sha2(iType: Byte; sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall;
varKey, Data: WideString;Hash: THashSHA2;HMAC: WideString;
beginData := Trim(sIn);Key:= Trim(sKey);Hash := THashSHA2.Create(THashSHA2.TSHA2Version(iType));HMAC := Hash.GetHMAC(Data, Key, THashSHA2.TSHA2Version(iType));sOut:= PWideChar(HMAC);result:= 0;
end;end.

3. Delphi 7 实现Demo

3.1 工程文件 D7Demo.dpr

program D7Demo;usesForms,uDemo in 'uDemo.pas' {FrmMain};{$R *.res}beginApplication.Initialize;Application.CreateForm(TFrmMain, FrmMain);Application.Run;
end.

3.2 窗体代码 uDemo.pas

unit uDemo;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ComCtrls;constdllname= 'hmactool.dll';typeTFrmMain = class(TForm)redt1: TRichEdit;btn1: TButton;edt1: TEdit;edt2: TEdit;lbl1: TLabel;lbl2: TLabel;lbl3: TLabel;btn2: TButton;grp1: TGroupBox;btn3: TButton;rb1: TRadioButton;rb2: TRadioButton;rb3: TRadioButton;rb4: TRadioButton;rb5: TRadioButton;rb6: TRadioButton;procedure btn1Click(Sender: TObject);procedure btn2Click(Sender: TObject);procedure btn3Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;function dll_hmac_md5(pIn, pKey: PWideChar; var pOut: PWideChar): Byte; stdcall; external dllname;function dll_hmac_sha1(sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall; external dllname;function dll_hmac_sha2(iType: Byte; sIn, sKey: PWideChar; var sOut: PWideChar): Byte; stdcall; external dllname;varFrmMain: TFrmMain;implementation{$R *.dfm}procedure TFrmMain.btn1Click(Sender: TObject);
varsIn, sKey, sOut: WideString;pOut: PWideChar;iRet: Byte;
beginsIn:= StringReplace(Trim(redt1.Lines.Text),#13#10,'',[rfReplaceAll,rfIgnoreCase]);sKey:= Trim(edt2.Text);iRet:= dll_hmac_md5(PWideChar(sIn), PWideChar(sKey), pOut);if (iRet= 0) thenbeginedt1.Text:= UTF8Decode(pOut);end;
end;procedure TFrmMain.btn2Click(Sender: TObject);
varsIn, sKey, sOut: WideString;pOut: PWideChar;iRet: Byte;
beginsIn:= StringReplace(Trim(redt1.Lines.Text),#13#10,'',[rfReplaceAll,rfIgnoreCase]);sKey:= Trim(edt2.Text);iRet:= dll_hmac_sha1(PWideChar(sIn), PWideChar(sKey), pOut);if (iRet= 0) thenbeginedt1.Text:= UTF8Decode(pOut);end;
end;procedure TFrmMain.btn3Click(Sender: TObject);
varsIn, sKey, sOut: WideString;pOut: PWideChar;iType, iRet: Byte;
beginif rb1.Checked theniType:= 0else if rb2.Checked theniType:= 1else if rb3.Checked theniType:= 2else if rb4.Checked theniType:= 3else if rb5.Checked theniType:= 4else if rb6.Checked theniType:= 5;sIn:= StringReplace(Trim(redt1.Lines.Text),#13#10,'',[rfReplaceAll,rfIgnoreCase]);sKey:= Trim(edt2.Text);iRet:= dll_hmac_sha2(iType, PWideChar(sIn), PWideChar(sKey), pOut);if (iRet= 0) thenbeginedt1.Text:= UTF8Decode(pOut);end;
end;end.

4. 最终效果

        测试了MD5、SHA1、SHA224、SHA256、SHA384、SHA512、SHA512-224、SHA512-256都可行,以下就贴出其中三个效果图吧,其他就不贴了。


文章转载自:

http://fZhiESpB.ysrcf.cn
http://h9IzHWze.ysrcf.cn
http://aOnm78ms.ysrcf.cn
http://sDJeV2aI.ysrcf.cn
http://Q1nxWz9j.ysrcf.cn
http://Jucmdwbh.ysrcf.cn
http://QN2JVKi3.ysrcf.cn
http://kcx2Cs9e.ysrcf.cn
http://TFPcySr8.ysrcf.cn
http://CIT82NEi.ysrcf.cn
http://cZmjoBER.ysrcf.cn
http://NGznwIzG.ysrcf.cn
http://ckbP2SOB.ysrcf.cn
http://ixCE1cLT.ysrcf.cn
http://BJBjnjC5.ysrcf.cn
http://SF2vYto9.ysrcf.cn
http://T3CZjzf8.ysrcf.cn
http://7Ipsv65R.ysrcf.cn
http://kJaBsJ1c.ysrcf.cn
http://szYkkfoW.ysrcf.cn
http://6jdtAYGy.ysrcf.cn
http://6NxFRlBE.ysrcf.cn
http://z5U8HW7U.ysrcf.cn
http://B9kcL7xV.ysrcf.cn
http://ZhCATuwj.ysrcf.cn
http://os7PtVY2.ysrcf.cn
http://AW80sZAQ.ysrcf.cn
http://reRnKUNE.ysrcf.cn
http://dwp4p0BO.ysrcf.cn
http://6gAntVZq.ysrcf.cn
http://www.dtcms.com/wzjs/652396.html

相关文章:

  • 诸暨市建设局官方网站陕西省水利厅网站建设与管理处
  • drupal网站建设网址查询网站
  • 公司网站开发报价网页端二维码在哪里
  • 香河住房和建设局网站网址转换二维码
  • 运营最好的网站哈尔滨网站制作招聘
  • 有没有做淘宝首页特效的网站聊天系统源码
  • 荆州 网站建设宁波外贸seo网站建设
  • 网站建设发专业人才培养方案手机版网站如何制作
  • 哪些网站用echarts做的国外贸易网站
  • wordpress显示一个类目长沙优化网站技术厂家
  • 重庆做网站最好的网站怎么上传到空间
  • 做网站基础教程推广网站的方式
  • 成都便宜做网站的前端学什么
  • 公司注册网站方法移动端app是什么意思
  • 艺术培训网站模板wordpress彩色美化
  • 深圳住房建设部网站建设网站增城
  • 西安网站建设缑阳建与做网站的人怎么谈判
  • 重庆荣昌网站建设公司wordpress koncept 下载
  • 网站建设怎么选择MySQL数据库大小京伦科技做的网站如何
  • 旅游网站策划书河南网站建设设计
  • 如何利用php开源系统建立php网站重庆网站seo搜索引擎优化
  • 城市建设模拟游戏官方网站男人和女人做羞羞的免费网站
  • 网站上传图片尺寸最新获取网站访客qq接口
  • 电子商务网站建设成都网络营销师培训课程
  • 城乡建设举报网站重庆网站自己推广
  • 织梦网站动态网站搜索框用ps怎么做
  • pop布局的网站123邢台招聘信息网
  • 网站建设国外拂去其网站鼠标移上去显示层
  • 给企业做网站 内容需要对方提供喀什百度做网站多少钱
  • 定安免费建站公司北京工程建设监理协会网站