2 * Novacoin classes library
3 * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 using System.Collections.Generic;
21 using Org.BouncyCastle.Math.EC;
22 using Org.BouncyCastle.Crypto.Parameters;
27 /// Representation of ECDSA public key
29 public class CPubKey : CKey
32 /// Initializes a new instance of CPubKey class as the copy of another instance
34 /// <param name="pubKey">Another CPubKey instance</param>
35 public CPubKey(CPubKey pubKey)
37 _Public = pubKey._Public;
41 /// Initializes a new instance of CPubKey class using supplied sequence of bytes
43 /// <param name="bytes">Byte sequence</param>
44 public CPubKey(IEnumerable<byte> bytes)
46 ECPoint pQ = curve.Curve.DecodePoint(bytes.ToArray());
47 _Public = new ECPublicKeyParameters(pQ, domain);
51 /// Init with base58 encoded sequence of bytes
53 /// <param name="strBase58"></param>
54 public CPubKey(string strBase58)
56 ECPoint pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray());
57 _Public = new ECPublicKeyParameters(pQ, domain);
61 /// Quick validity test
63 /// <returns>Validation result</returns>
66 get { return !_Public.Q.IsInfinity; }
71 return Interop.ToHex(PublicBytes);
74 public override string ToString()
76 List<byte> r = new List<byte>();
78 r.Add((byte)(AddrType.PUBKEY_ADDRESS));
79 r.AddRange(PublicBytes);
81 return AddressTools.Base58EncodeCheck(r);