我如何在 C# 中获取 sha3-512 哈希?

How can i get sha3-512 hash in C#?

exaple,string "test"在https://md5calc.com/hash/sha3-512/test给我“ 9ece086e9bac491fac491fac5c1d1046ca11d737b97b92a2ab92ab92ab2b2 ebd93f005557b7b7b7b7b7b7b7110110110c01110c01782882888888888888888888888888888888888812e1912e1921.21ry.1pc.1rp21ryp22e1ry.2ccapca a.1 cca a.888881 cca a.1 cca a.1 cc.1 cc.1 ccy71 cca

但是

using HashLib; // from https://www.nuget.org/packages/HashLib
using System;

class Program
{
    static void Main(string[] args)
    {
        var sha3512 = HashFactory.Crypto.SHA3.CreateKeccak512();
        var tempHash = sha3512.ComputeString("test");
        Console.WriteLine(tempHash.ToString().ToLower().Replace("-", ""));
    }
}

returns “3abff7b1f2042ac3861bd4c0b40efaa8a695909bfb31753fc7b1bd69778de1225a627c8f07cf4814cc05435ada2a1ffee3f4513a8867154274787624f24e551b”

我需要获取第一个字符串,而不是 hashlib 提供的。

您可以使用 BouncyCastle。它有一个 SHA3 实现。

var hashAlgorithm = new Org.BouncyCastle.Crypto.Digests.Sha3Digest(512);

// Choose correct encoding based on your usecase
byte[] input = Encoding.ASCII.GetBytes("test");

hashAlgorithm.BlockUpdate(input, 0, input.Length);

byte[] result = new byte[64]; // 512 / 8 = 64
hashAlgorithm.DoFinal(result, 0);

string hashString = BitConverter.ToString(result);
hashString = hashString.Replace("-", "").ToLowerInvariant();

Console.WriteLine(hashString);

输出为

9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7b710110c0a678288166e7fbe796883a4f2e9b3ca9f484f521d0ce464345cc1aec96779149c14