using System; using System.Text; using System.Linq; using System.Collections.Generic; namespace Novacoin { /// /// Representation of SHA-256 hash /// public class Hash256 { // 32 bytes const int hashSize = 32; /// /// Array of digest bytes. /// private byte[] hashBytes = new byte[hashSize]; /// /// Initializes an empty instance of the Hash256 class. /// public Hash256() { hashBytes = Enumerable.Repeat(0, hashSize).ToArray(); } /// /// Initializes a new instance of Hash256 class with first 32 bytes from supplied list /// /// List of bytes public Hash256(List bytesList) { hashBytes = bytesList.Take(hashSize).ToArray(); } public Hash256(byte[] bytesArray) { hashBytes = bytesArray; } public override string ToString() { StringBuilder sb = new StringBuilder(hashSize * 2); foreach (byte b in hashBytes) { sb.AppendFormat("{0:x2}", b); } return sb.ToString(); } } }