1 \feffusing System.Security.Cryptography;
2 using System.Collections.Generic;
7 public abstract class Hash
10 /// Computes the SHA256 hash for the input data using the managed library.
12 protected static SHA256Managed _hasher256 = new SHA256Managed();
15 /// Array of digest bytes.
17 protected byte[] _hashBytes = null;
20 /// Hash size, must be overriden
22 public virtual int hashSize
28 public byte[] hashBytes
30 get { return _hashBytes; }
34 /// Initializes an empty instance of the Hash class.
38 _hashBytes = Enumerable.Repeat<byte>(0, hashSize).ToArray();
42 /// Initializes a new instance of Hash class with first 20 bytes from supplied list
44 /// <param name="bytesList">List of bytes</param>
45 public Hash(IList<byte> bytesList)
47 _hashBytes = bytesList.Take<byte>(hashSize).ToArray<byte>();
50 public Hash(byte[] bytesArray)
52 _hashBytes = bytesArray;
57 return !_hashBytes.Any(b => b != 0);
60 public override string ToString()
62 return Interop.ToHex(Interop.ReverseBytes(_hashBytes));