简单实现SHA-3 Keccak散列到C#的错误输出?

1 c# hash sha-3 keccak

我会简短而简单!我正在学习C#,我正在努力让HashLib库@ https://hashlib.codeplex.com/为新的SHA-3 Keccak算法工作.我写了一个简单的Console/Win32应用程序,据说必须输出正确的哈希码,但事实并非如此!

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();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序构建并运行正常,但输出非常错误.当我使用其他人的Keccak算法实现时,我会得到不同的结果,并且它也不匹配,例如这个wiki帖子.https://en.wikipedia.org/wiki/SHA-3所以事情显然是错误的.

当我将文本留空时,例如,我得到以下内容:"df987cfd23fbc92e7e87faaca300ec3f等等" 虽然维基和其他工具说我应该得到

"0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e"

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

有没有人有建议?

Dav*_*rtz 6

您的HashLib版本太旧了.如果您查看最近的更改,您可以看到测试向量从您获得的更改为您应该获得的更改.(当然,算法也改变了.)