简单的实现SHA-3 Keccak的散列在C#中的错误输出? [英] Simple implementation of SHA-3 Keccak hashing to the wrong output in C#?

查看:359
本文介绍了简单的实现SHA-3 Keccak的散列在C#中的错误输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会尽量简短,简单!我正在学习C#和我试图让HashLib库@ https://hashlib.codeplex.com/为新的SHA-3 Keccak算法工作。我已经写了理应有输出正确的哈希码一个简单的控制台/ Win32应用程序,但它不会!

I'll keep it short and simple! I'm learning C#, and I am trying to get the HashLib library @ https://hashlib.codeplex.com/ working for the new SHA-3 Keccak algorithm. I've written a simple Console/Win32 application that supposedly has to output the correct hash code, but it doesn't!

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 因此,一些明显。错了

The application builds and runs ok, but the output is very wrong. When I use other people 's implementations of the Keccak algorithm, I get different results and it doesn't match for example this wiki post either. https://en.wikipedia.org/wiki/SHA-3 So something is obviously wrong.

当我离开文本空,按例如,我得到了以下内容:df987cfd23fbc92e7e87faaca300ec3f等等,等等而维基和其他工具,说我应该得到

When I leave the text empty, as per example, I get the following: "df987cfd23fbc92e7e87faaca300ec3f etc. etc." while the wiki and other tools say I should get

0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e

"0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e"

,这是完全不同的东西。我也当然非空字符串试了一下​​。

,which is something entirely different. I also tried it with non-empty strings of course.

有没有人有一个建议?

推荐答案

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

Your version of HashLib is too old. If you look at the recent changes you can see the test vector changed from the one you got to the one you should get. (The algorithm changed as well, of course.)

这篇关于简单的实现SHA-3 Keccak的散列在C#中的错误输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆