2 using System.Security.Cryptography;
3 using System.Collections.Generic;
6 using System.Threading.Tasks;
10 public abstract class Hash
13 /// Computes the SHA256 hash for the input data using the managed library.
15 protected static SHA256Managed _hasher256 = new SHA256Managed();
18 /// Array of digest bytes.
20 protected byte[] _hashBytes = null;
23 /// Hash size, must be overriden
25 public virtual int hashSize
31 public byte[] hashBytes
33 get { return _hashBytes; }
37 /// Initializes an empty instance of the Hash class.
41 _hashBytes = Enumerable.Repeat<byte>(0, hashSize).ToArray();
45 /// Initializes a new instance of Hash class with first 20 bytes from supplied list
47 /// <param name="bytesList">List of bytes</param>
48 public Hash(IList<byte> bytesList)
50 _hashBytes = bytesList.Take<byte>(hashSize).ToArray<byte>();
53 public Hash(byte[] bytesArray)
55 _hashBytes = bytesArray;
58 public override string ToString()
60 return Interop.ToHex(_hashBytes);