1 \feffusing System.Collections.Generic;
3 using Org.BouncyCastle.Math.EC;
4 using Org.BouncyCastle.Crypto.Parameters;
9 /// Representation of ECDSA public key
11 public class CPubKey : CKey
14 /// Initializes a new instance of CPubKey class as the copy of another instance
16 /// <param name="pubKey">Another CPubKey instance</param>
17 public CPubKey(CPubKey pubKey)
19 _Public = pubKey._Public;
23 /// Initializes a new instance of CPubKey class using supplied sequence of bytes
25 /// <param name="bytes">Byte sequence</param>
26 public CPubKey(IEnumerable<byte> bytes)
28 ECPoint pQ = curve.Curve.DecodePoint(bytes.ToArray());
29 _Public = new ECPublicKeyParameters(pQ, domain);
33 /// Init with base58 encoded sequence of bytes
35 /// <param name="strBase58"></param>
36 public CPubKey(string strBase58)
38 ECPoint pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray());
39 _Public = new ECPublicKeyParameters(pQ, domain);
43 /// Quick validity test
45 /// <returns>Validation result</returns>
48 get { return !_Public.Q.IsInfinity; }
53 return Interop.ToHex(Public);
56 public override string ToString()
58 List<byte> r = new List<byte>();
60 r.Add((byte)(AddrType.PUBKEY_ADDRESS));
64 return AddressTools.Base58EncodeCheck(r);