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 abstract int hashSize
27 public byte[] hashBytes
29 get { return _hashBytes; }
33 /// Initializes an empty instance of the Hash class.
37 _hashBytes = Enumerable.Repeat<byte>(0, hashSize).ToArray();
41 /// Initializes a new instance of Hash class with first 20 bytes from supplied list
43 /// <param name="bytesList">List of bytes</param>
44 public Hash(IEnumerable<byte> bytes)
46 _hashBytes = bytes.Take<byte>(hashSize).ToArray<byte>();
49 public Hash(byte[] bytes)
56 h._hashBytes.CopyTo(_hashBytes, 0);
61 get { return !_hashBytes.Any(b => b != 0); }
64 public override string ToString()
66 return Interop.ToHex(Interop.ReverseBytes(_hashBytes));