2 using System.Collections.Generic;
5 using System.Threading.Tasks;
9 public abstract class Hash
12 /// Array of digest bytes.
14 private byte[] _hashBytes = null;
17 /// Hash size, must be overriden
19 public virtual int hashSize
25 public IList<byte> hashBytes
27 get { return new List<byte>(_hashBytes); }
31 /// Initializes an empty instance of the Hash class.
35 _hashBytes = Enumerable.Repeat<byte>(0, hashSize).ToArray();
39 /// Initializes a new instance of Hash class with first 20 bytes from supplied list
41 /// <param name="bytesList">List of bytes</param>
42 public Hash(IList<byte> bytesList)
44 _hashBytes = bytesList.Take<byte>(hashSize).ToArray<byte>();
47 public Hash(byte[] bytesArray)
49 _hashBytes = bytesArray;
52 public override string ToString()
54 StringBuilder sb = new StringBuilder(hashSize * 2);
55 foreach (byte b in _hashBytes)
57 sb.AppendFormat("{0:x2}", b);