5b23d602f4f5192c3baf5c0fae6c43110dbea316
[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[] bytes) : base(bytes) { }
27         public Hash160(IEnumerable<byte> bytes) : base(bytes) { }
28         public Hash160(Hash160 h) : base(h) { }
29
30         public static Hash160 Compute160(IEnumerable<byte> inputBytes)
31         {
32             byte[] dataBytes = inputBytes.ToArray();
33             byte[] digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length);
34             byte[] digest2 = _hasher160.ComputeHash(digest1, 0, digest1.Length);
35
36             return new Hash160(digest2);
37         }
38         }
39 }
40