【发布时间】:2012-12-27 21:05:30
【问题描述】:
我正在尝试让 HashLib 库 @https://hashlib.codeplex.com/ 为新的 SHA-3 Keccak 算法工作。我编写了一个简单的控制台应用程序,据说它必须输出正确的哈希码,但事实并非如此!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using HashLib;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
{
string passPhrase = "";
IHash hash = HashFactory.Crypto.SHA3.CreateKeccak512();
HashResult r = hash.ComputeString(passPhrase, System.Text.Encoding.ASCII);
Console.WriteLine(r.ToString().ToLower().Replace("-",""));
Console.WriteLine("{0}, {1}, {2}", hash.BlockSize, hash.HashSize, hash.Name);
Console.ReadLine();
}
}
}
}
应用程序构建并运行正常,但输出非常错误。当我使用其他人的 Keccak 算法实现时,我得到不同的结果,并且它也不匹配,例如这个 wiki 帖子。 https://en.wikipedia.org/wiki/SHA-3 显然有问题。
当我将文本留空时,例如,我得到以下信息:“df987cfd23fbc92e7e87faaca300ec3f etc. etc.”而维基和其他工具说我应该得到
“0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdb33d3670680e”
,这是完全不同的东西。当然,我也尝试过使用非空字符串。
有人有什么建议吗?
【问题讨论】:
-
看起来像是其中一种实现或您的检查值错误。可能他们在将 IV 命名为 SHA-3 时更改了 IV,以使其哈希值与 Keccak 不同。
-
看起来你得到的值也是 SHA-3 -256 的值,我会亲自更新 HashLib 并获取最新版本
-
大卫,很抱歉,最新的代码(变更集 78295)没有解决问题。当我使用以下代码时,IHash hash = HashFactory.Crypto.SHA3.CreateKeccak512(); HashResult res = hash.ComputeString("", System.Text.Encoding.ASCII);字符串 dd = res.ToString();在我的VS 2012 IDE中,我得到了一个结果作为DF987CFD-23FBC92E-7E87FAAC-A300EC3F-AA1DBADC-678E8EE9-4A830968-F22D9209-64AB402D-C5D0F7B2-0C9644BE-08056555-08056555- 8BDA3DF9-8C95-8BDA3DF9-8C95-8BDA3DF9-8C94BACC-EA25D3C1与指定的问题相同我不确定更改是否到位当我使用从文件中获取的测试向量时