c#中SHA-3 Keccak散列错误输出的简单实现

本文关键字:输出 简单 实现 错误 SHA-3 Keccak | 更新日期: 2023-09-27 17:49:45

我正试图让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等等"而维基和其他工具说我应该得到

"0 eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e"

是完全不同的东西。当然,我也尝试过非空字符串。

有人有什么建议吗?

c#中SHA-3 Keccak散列错误输出的简单实现

您的HashLib版本太旧了。如果你看一下最近的变化你可以看到测试向量从你得到的变成了你应该得到的。(当然,算法也改变了)