Mapping 256Bit Hash to 32Bit Indexed Hash
using System.Security.Cryptography;
public class Mapping256BitTo32BitHash : HashAlgorithm
{
private readonly SHA256Managed hasher = new SHA256Managed();
public readonly TinyDictionary<byte[], byte[]> map = new TinyDictionary<byte[], byte[]>(101, new ArrayComparer());
private byte[] h160;
public override int HashSize => 32;
public override void Initialize()
{
}
protected override void HashCore(byte[] bytes, int ibStart, int cbSize)
{
h160 = hasher.ComputeHash(bytes, ibStart, cbSize);
map.Add(h160, bytes);
}
protected override byte[] HashFinal()
{
HashValue = (byte[])map.FindKeyIndex(h160).GetBytes().Clone();
return HashValue;
}
}
using System.Security.Cryptography;
public class Mapping256BitTo32BitHash : HashAlgorithm
{
private readonly SHA256Managed hasher = new SHA256Managed();
public readonly TinyDictionary<byte[], byte[]> map = new TinyDictionary<byte[], byte[]>(101, new ArrayComparer());
private byte[] h160;
public override int HashSize => 32;
public override void Initialize()
{
}
protected override void HashCore(byte[] bytes, int ibStart, int cbSize)
{
h160 = hasher.ComputeHash(bytes, ibStart, cbSize);
map.Add(h160, bytes);
}
protected override byte[] HashFinal()
{
HashValue = (byte[])map.FindKeyIndex(h160).GetBytes().Clone();
return HashValue;
}
}
using System.Security.Cryptography; public class Mapping256BitTo32BitHash : HashAlgorithm { private readonly SHA256Managed hasher = new SHA256Managed(); public readonly TinyDictionary<byte[], byte[]> map = new TinyDictionary<byte[], byte[]>(101, new ArrayComparer()); private byte[] h160; public override int HashSize => 32; public override void Initialize() { } protected override void HashCore(byte[] bytes, int ibStart, int cbSize) { h160 = hasher.ComputeHash(bytes, ibStart, cbSize); map.Add(h160, bytes); } protected override byte[] HashFinal() { HashValue = (byte[])map.FindKeyIndex(h160).GetBytes().Clone(); return HashValue; } }