当前位置: 首页 > 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://www.dtcms.com/wzjs/154377.html

相关文章:

  • 互动平台论坛湘潭seo公司
  • 青岛做外贸网站哪家好中国最大网站排名
  • 深圳集团网站开发公司常见的网络营销方法有哪些
  • 宁波做网站的公司一个品牌的策划方案
  • app下载官方网站深圳网络推广哪家公司好
  • 福州网站营销百度有免费推广广告
  • 温州网站开发多少钱google store
  • win网站建设网站seo收费
  • 坛墨网站建设头条指数
  • 网站建设宗旨及商业模式竞价推广套户渠道商
  • wordpress内部优化谷歌seo什么意思
  • 计算网站制作教程小型项目外包网站
  • 网站建设具体详细过程广东最新疫情
  • 用html做的游戏网站免费观看行情软件网站下载
  • 个人博客首页seo排名点击首页
  • 日本做h动漫电影网站郑州网站制作公司
  • 珠海舒讯网站建设长沙网站快速排名提升
  • 网站建设情况说明书青岛自动seo
  • 做企业网站 签合同要注意什么汕头网站建设方案开发
  • 天津注册公司多少钱百度seo 优化
  • 全新域名请收藏seo技术优化技巧
  • 那个网站是做房产中介的宁波网站制作与推广价格
  • 网站收录怎么弄深圳市住房和建设局
  • 外贸公司的网站建设模板下载西地那非片吃了多久会硬起来
  • 北京市专业网站制作企业营销型网站外包
  • 购物网站开发项目意义郑州网站优化公司
  • axure怎么做响应式网站北京seo优化wyhseo
  • 网易云播放器做网站播放中国十大外贸平台
  • 建设门户网站请示宁波seo快速优化
  • wordpress简单的验证码北京seo排名服务