/// <summary>
        /// Get public key from private key.
        /// </summary>
        /// <param name="scheme">Used scheme.</param>
        /// <param name="privateKey">Private key bytes.</param>
        /// <returns>Public key.</returns>
        public GXPublicKey GetPublicKey()
        {
            GXBigInteger secret = new GXBigInteger(RawValue);
            GXCurve      curve  = new GXCurve(Scheme);
            GXEccPoint   p      = new GXEccPoint(curve.G.x, curve.G.y, new GXBigInteger(1));

            p = GXEcdsa.JacobianMultiply(p, secret, curve.N, curve.A, curve.P);
            GXEcdsa.FromJacobian(p, curve.P);
            GXByteBuffer key = new GXByteBuffer(65);

            //Public key is un-compressed format.
            key.SetUInt8(4);
            byte[] tmp = p.x.ToArray();
            key.Set(tmp, tmp.Length % 32, 32);
            tmp = p.y.ToArray();
            key.Set(tmp, tmp.Length % 32, 32);
            return(GXPublicKey.FromRawBytes(key.Array()));
        }
예제 #2
0
 /// <summary>
 /// Get public key from private key.
 /// </summary>
 /// <param name="scheme">Used scheme.</param>
 /// <param name="privateKey">Private key bytes.</param>
 /// <returns>Public key.</returns>
 public GXPublicKey GetPublicKey()
 {
     if (publicKey == null)
     {
         GXBigInteger pk    = new GXBigInteger(RawValue);
         GXCurve      curve = new GXCurve(Scheme);
         GXEccPoint   p     = new GXEccPoint(curve.G.x, curve.G.y, new GXBigInteger(1));
         p = GXEcdsa.JacobianMultiply(p, pk, curve.N, curve.A, curve.P);
         GXEcdsa.FromJacobian(p, curve.P);
         GXByteBuffer key = new GXByteBuffer(65);
         //Public key is un-compressed format.
         key.SetUInt8(4);
         byte[] tmp  = p.x.ToArray();
         int    size = Scheme == Ecc.P256 ? 32 : 48;
         key.Set(tmp, tmp.Length % size, size);
         tmp = p.y.ToArray();
         key.Set(tmp, tmp.Length % size, size);
         publicKey = GXPublicKey.FromRawBytes(key.Array());
     }
     return(publicKey);
 }