Вопрос

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 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();
            }
        }
    }
}

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.

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"

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

Does anyone have a suggestion?

Это было полезно?

Решение

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.)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top