most instensive multihash in csharp

One way to perform multi-hash in C# is by using the System.Security.Cryptography namespace.

Here's an example of how to perform multi-hash using SHA256 and SHA512 algorithms:

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

public static class MultiHash
{
    public static string Compute(string data)
    {
        byte[] bytes = Encoding.UTF8.GetBytes(data);
        
        byte[] hash256, hash512, result;
        
        using (SHA256 sha256 = SHA256.Create())
        {
            hash256 = sha256.ComputeHash(bytes);
        }
        
        using (SHA512 sha512 = SHA512.Create())
        {
            hash512 = sha512.ComputeHash(bytes);
        }
        
        result = new byte[hash256.Length + hash512.Length];
        hash256.CopyTo(result, 0);
        hash512.CopyTo(result, hash256.Length);
        
        return Convert.ToBase64String(result);
    }
}
711 chars
29 lines

You can call the Compute method by passing a string data as parameter, which will return the multi-hash in base64 string format.

Note that multi-hash is a concept about concatenation of multiple hash functions, so the order of hashes concatenation and the hash function used are up to you.

gistlibby LogSnag