Multihash implementation in C#
$ dotnet add package Nethermind.Multiformats.HashMultibase implementation in C#.
This is not a general purpose hashing library, but a library to encode/decode Multihashes which is a "container" describing what hash algorithm the digest is calculated with. The library also support calculating the digest, but that is not it's main purpose. If you're looking for a library that supports many algorithms and only want the raw digest, try BouncyCastle or the built-ins of the .net framework.
To be clear, when you calculate a digest (using Sum) with this library, you will get a byte array including a prefix with the properties of the algorithm used (type and length).
There's a CLI version that you can use to compute files or direct input from the command line. This CLI tool passes the sharness tests here.
PM> Install-Package Multiformats.Hash
dotnet add package Multiformats.Hash
// decode a multihash formatted byte array
Multihash mh = Multihash.Decode(bytes);
// decode a multihash formatted string
Multihash mh = Multihash.Parse(str);
bool ok = Multihash.TryParse(str, out mh);
// encode a digest to multiformat byte array
byte[] bytes = Multihash.Encode(digest, HashType.SHA1);
byte[] bytes = Multihash.Encode<SHA1>(digest);
// calculate digest
Multihash mh = Multihash.Sum<SHA1>(bytes);
// verify
bool isValid = mh.Verify(bytes);