求delphi7 下实现Hamc sha384加密算法的方法

wuleiieluw 2015-02-22 03:16:08
如题。求在delphi7 下实现Hamc sha384加密算法的方法。就是带密匙的那种!
...全文
387 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuleiieluw 2015-02-24
  • 打赏
  • 举报
回复
13楼,正解!
lyhoo163 2015-02-23
  • 打赏
  • 举报
回复
密切关注了。
pathletboy 2015-02-23
  • 打赏
  • 举报
回复
golang也是这个结果,所以,确定cryptojs是错误的。 http://ideone.com/NzEqQu
pathletboy 2015-02-23
  • 打赏
  • 举报
回复
你找的这俩个网站,都用的CryptoJS,同个库,个人认为软件正确的可能性高。
wuleiieluw 2015-02-23
  • 打赏
  • 举报
回复

明文是:'abcdefg'
密匙是:’123456‘

又换了家网站,hamc-sha384计算结果还是
407ed......1c66



也奇葩了!就是384不一样。
其他的,都核对无误!!

到底是哪个对!?
pathletboy 2015-02-23
  • 打赏
  • 举报
回复
你找的那网站计算有问题罢了,我这边用第三方算hash的工具验算是正确的。
wuleiieluw 2015-02-23
  • 打赏
  • 举报
回复


我用在线加密网站验算了下。


这个才应该是正确的答案。你是不是那里调用错了?
wuleiieluw 2015-02-23
  • 打赏
  • 举报
回复
明文是:'abcdefg'
密匙是:’123456‘

得出这个结果,不正确吧!?
pathletboy 2015-02-22
  • 打赏
  • 举报
回复
引用 5 楼 wuleiieluw 的回复:
解压的项目,一编译就报错

error('compile with $define DLL');

错在这句上。具体怎么用啊?


复制出以下文件到你自己的工程
btypes.pas
hash.pas
hmac.pas
hmacsha3.pas(楼上已经给出)
sha256.pas
sha384.pas
sha512.pas
std.inc

调用范例
program hmac_sha384_example;

{$APPTYPE CONSOLE}

uses
SysUtils, hmac, hash, hmacsha3;


const
data = 'abcdefg';
key = '123456';

var
HMacContent: THMAC_Context;
mac: TSHA384Digest;
i: Integer;

begin
hmac_SHA384_init(HMacContent, PChar(key), Length(key));
hmac_SHA384_updateXL(HMacContent, PChar(data), Length(data));
hmac_SHA384_final(HMacContent, mac);
for i := 0 to Length(mac) do
Write(Format('%.2x',[mac[i]]));
Readln;
end.


运行结果
wuleiieluw 2015-02-22
  • 打赏
  • 举报
回复
解压的项目,一编译就报错 error('compile with $define DLL'); 错在这句上。具体怎么用啊?
wuleiieluw 2015-02-22
  • 打赏
  • 举报
回复
要生成Dll,然后调用动态联结库?
小弟愚笨,想弱弱的问下,具体怎么用啊?
例如
明文是:'abcdefg'
密匙是:’123456‘

参数该往那里填?结果又从那里得到?
pathletboy 2015-02-22
  • 打赏
  • 举报
回复
下面是改好的384
unit HMACSHA3;

interface

{$i STD.INC}

uses
  BTypes,Hash,HMAC,SHA384;


procedure hmac_SHA384_init(var ctx: THMAC_Context; key: pointer; klen: word);
  {-initialize HMAC context with key}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA384_inits(var ctx: THMAC_Context; skey: Str255);
  {-initialize HMAC context with skey}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA384_update(var ctx: THMAC_Context; data: pointer; dlen: word);
  {-HMAC data input, may be called more than once}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA384_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
  {-HMAC data input, may be called more than once}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA384_final(var ctx: THMAC_Context; var mac: TSHA384Digest);
  {-end data input, calculate HMAC digest}
  {$ifdef DLL} stdcall; {$endif}

implementation


{---------------------------------------------------------------------------}
procedure hmac_SHA384_init(var ctx: THMAC_Context; key: pointer; klen: word);
  {-initialize HMAC context with key}
var
  phash: PHashDesc;
begin
  phash := FindHash_by_ID(_SHA384);
  hmac_init(ctx, phash, key, klen);
end;


{---------------------------------------------------------------------------}
procedure hmac_SHA384_inits(var ctx: THMAC_Context; skey: Str255);
  {-initialize HMAC context with skey}
begin
  hmac_SHA384_init(ctx, @skey[1], length(skey));
end;


{---------------------------------------------------------------------------}
procedure hmac_SHA384_update(var ctx: THMAC_Context; data: pointer; dlen: word);
  {-HMAC data input, may be called more than once}
begin
  hmac_updateXL(ctx, data, dlen);
end;


{---------------------------------------------------------------------------}
procedure hmac_SHA384_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
  {-HMAC data input, may be called more than once}
begin
  hmac_updateXL(ctx, data, dlen);
end;


{---------------------------------------------------------------------------}
procedure hmac_SHA384_final(var ctx: THMAC_Context; var mac: TSHA384Digest);
  {-end data input, calculate HMAC digest}
var
  d: THashDigest;
begin
  hmac_final(ctx, d);
  move(d, mac, sizeof(mac));
end;

end.
pathletboy 2015-02-22
  • 打赏
  • 举报
回复
hmac sha256有现成的,把这个改sha384就可以,文件很简单,看下就能改。
pathletboy 2015-02-22
  • 打赏
  • 举报
回复
http://www.wolfgang-ehrhardt.de/crc_hash_2014-08-25.zip hmacsha2.pas
procedure hmac_SHA256_init(var ctx: THMAC_Context; key: pointer; klen: word);
  {-initialize HMAC context with key}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA256_inits(var ctx: THMAC_Context; skey: Str255);
  {-initialize HMAC context with skey}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA256_update(var ctx: THMAC_Context; data: pointer; dlen: word);
  {-HMAC data input, may be called more than once}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA256_updateXL(var ctx: THMAC_Context; data: pointer; dlen: longint);
  {-HMAC data input, may be called more than once}
  {$ifdef DLL} stdcall; {$endif}

procedure hmac_SHA256_final(var ctx: THMAC_Context; var mac: TSHA256Digest);
  {-end data input, calculate HMAC digest}
  {$ifdef DLL} stdcall; {$endif}

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧