VarInt class, TxIn/TXOut/Tx serializarion, some CKey and CPubKey methods
[NovacoinLibrary.git] / Novacoin / Hash160.cs
1 \feffusing System;
2 using System.Security.Cryptography;
3 using System.Collections.Generic;
4 using System.Text;
5 using System.Linq;
6
7 namespace Novacoin
8 {
9         /// <summary>
10         /// Representation of pubkey/script hash.
11         /// </summary>
12         public class Hash160 : Hash
13         {
14         /// <summary>
15         /// Computes RIPEMD160 hash using managed library
16         /// </summary>
17         private static readonly RIPEMD160Managed _hasher160 = new RIPEMD160Managed();
18         
19         // 20 bytes
20         public override int hashSize
21         {
22             get { return 20; }
23         }
24
25         public Hash160() : base() { }
26         public Hash160(byte[] bytesArray) : base(bytesArray) { }
27         public Hash160(IList<byte> bytesList) : base(bytesList) { }
28
29         public static Hash160 Compute160(IEnumerable<byte> inputBytes)
30         {
31             byte[] dataBytes = inputBytes.ToArray();
32             byte[] digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length);
33             byte[] digest2 = _hasher160.ComputeHash(digest1, 0, digest1.Length);
34
35             return new Hash160(digest2);
36         }
37         }
38 }
39