create a sha3_512 hash from a string in csharp

Here's how to create a SHA3_512 hash from a string in C#:

main.cs
using System.Security.Cryptography;
using System.Text;

public static string GetSha3_512Hash(string input)
{
    // Create a SHA3_512 hash object.
    using (var sha3_512 = SHA3.Create512())
    {
        // Convert the input string to a byte array.
        byte[] inputBytes = Encoding.UTF8.GetBytes(input);

        // Compute the hash value from the input byte array.
        byte[] hashBytes = sha3_512.ComputeHash(inputBytes);

        // Convert the hash byte array to a string.
        StringBuilder sb = new StringBuilder();
        foreach (byte b in hashBytes)
        {
            sb.Append(b.ToString("x2"));
        }
        return sb.ToString();
    }
}
670 chars
24 lines

You can call this function with a string input to get the SHA3_512 hash value for that input. Note that you'll need to include the System.Security.Cryptography and System.Text namespaces at the beginning of your code file to use this code.

gistlibby LogSnag