8ad4c3e648860e336690c253ce7c764bebb4620a
[NovacoinLibrary.git] / Novacoin / CPubKey.cs
1 \feffusing System.Collections.Generic;
2 using System.Linq;
3 using Org.BouncyCastle.Math.EC;
4 using Org.BouncyCastle.Crypto.Parameters;
5
6 namespace Novacoin
7 {
8     /// <summary>
9     /// Representation of ECDSA public key
10     /// </summary>
11     public class CPubKey : CKey
12     {
13         /// <summary>
14         /// Initializes a new instance of CPubKey class as the copy of another instance
15         /// </summary>
16         /// <param name="pubKey">Another CPubKey instance</param>
17         public CPubKey(CPubKey pubKey)
18         {
19             _Public = pubKey._Public;
20         }
21
22         /// <summary>
23         /// Initializes a new instance of CPubKey class using supplied sequence of bytes
24         /// </summary>
25         /// <param name="bytes">Byte sequence</param>
26         public CPubKey(IEnumerable<byte> bytes)
27         {
28             ECPoint pQ = curve.Curve.DecodePoint(bytes.ToArray());
29             _Public = new ECPublicKeyParameters(pQ, domain);
30         }
31
32         /// <summary>
33         /// Quick validity test
34         /// </summary>
35         /// <returns>Validation result</returns>
36         public bool IsValid
37         {
38             get { return !_Public.Q.IsInfinity; }
39         }
40
41         /// <summary>
42         /// Is this a compressed public key?
43         /// </summary>
44         /// <returns></returns>
45         public bool IsCompressed
46         {
47             get { return _Public.Q.IsCompressed; }
48         }
49
50         public override string ToString()
51         {
52             return Interop.ToHex(Public);
53         }
54     }
55 }