SHA 3 -512在 Delphi 7中的实现

c9qzyr3d  于 2023-04-29  发布在  其他
关注(0)|答案(1)|浏览(180)

我尝试使用 Delphi 7中https://github.com/TheLazyTomcat/lib.SHA3存储库中的SHA 3加密库,但是没有成功。项目使用库编译,但我不知道如何实现它。我想使用这个库从字符串生成SHA 3 -512哈希,但我不知道如何做到。有人能帮帮我吗
我开始了下面的代码,但我无法发展到解决方案:

procedure TForm1.Button1Click(Sender: TObject);
var
  Hasher: TSHA3_512Hash;
  Hash: TSHA3_512;
  Input: string;
  I: Integer;
begin
  Input := 'Hello, world!';

  Hasher := TSHA3_512Hash.Create;
  try
    Hasher.Init;
    Hasher.Update(Input[1], Length(Input) * SizeOf(Char));
    Hasher.HashString(Input);
    //Hash := Hasher.Final;
  finally
    Hasher.Free;
  end;

  {ShowMessage('Hash SHA-3 de ' + Input + ':'#13#10
              + '0x' + IntToHex(Hash[0], 2));
  for I := 1 to 63 do
    ShowMessage('0x' + IntToHex(Hash[I], 2));}
end;
x8diyxa7

x8diyxa71#

program Demo;
{$APPTYPE CONSOLE}

uses
  SHA3;  // ...which needs AuxTypes, HashBase, AuxClasses, BitOps, StaticMemoryStream, StrRect, SimpleCPUID

var
  Hasher: TSHA3_512Hash;
begin
  Hasher:= TSHA3_512Hash.Create;
  try
    // Calling Hasher.Init() is not needed, as it is already done in THashBase.HashBuffer().
    Hasher.HashString( 'ABCD1234' );  // As per Delphi 7 these 8 characters equal 8 bytes.
    Writeln( Hasher.AsString() );  // That's it. Calling Hasher.Final() would raise an exception.
  finally
    Hasher.Free;
  end;
end.

输出为(我插入的空格):
D713A871 E75F8223 6D0396C6 7474F1F6 96181797 24584D55 4792F059 5E35F414 892C9B72 21058B0F FB3B1236 6901F25C 6A5BB5F7 19EB5A65 94D9C63F FDE1CDDB
https://www.browserling.com/tools/sha3-hash的结果相比,https://www.browserling.com/tools/sha3-hash也是:
d713a871 e75f8223 6d0396c6 7474f1f6 96181797 24584d55 4792f059 5e35f414 892c9b72 21058b0f fb3b1236 6901f25c 6a5bb5f7 19eb5a65 94d9c63f fde1cddb
如你所见:这很简单:
1.调用.HashString()来处理所需的字节。
1.通过.AsString()获取二进制哈希和的十六进制表示。

相关问题