我正在尝试使用Wolfgang Ehrardt的CRC/哈希库,使用SHA3/256算法对字符串进行哈希。
我编写了以下过程:
procedure TForm1.Button1Click(Sender: TObject);
var
Context : THashContext;
Digest: TSHA3_256Digest;
buf: TBytes;
s: string;
begin
buf := TEncoding.UTF8.GetBytes('0123456789012345');
SHA3_256Full(Digest, buf, SizeOF(buf));
s:=HexStr(@Digest, SizeOf(Digest)); //HexStr is in mem_utils unit from the same CRC/Hash library
memo1.lines.clear;
memo1.Lines.add(s);
end;
生成的哈希值为 b64f67d4a6fe871afc5c42e3128b5e3b6943c475bab1a138667c0213e1f9a6bb,但与在http://emn178.github.io/online-tools/sha3_256.html 上使用 SHA-3/256 工具得到的结果不同。在该网站上,相同的字符串生成的哈希值是4e058e17199441d69589d3c775face0c4949af7f4f011317efce2fc22606c428。
另一方面,如果尝试对一个空字符串进行哈希,结果是a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a,这是正确的。
因此问题是:我的代码有什么错误吗?