Ejemplo n.º 1
0
        public PubKey GetSharedPubkey(Key key)
        {
#if HAS_SPAN
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            return(new PubKey(ECKey.GetSharedPubkey(key._ECKey), true));
#else
            var pub     = _ECKey.GetPublicKeyParameters();
            var privKey = key._ECKey.PrivateKey;
            if (!pub.Parameters.Equals(privKey.Parameters))
            {
                throw new InvalidOperationException("ECDH public key has wrong domain parameters");
            }
            ECPoint q = pub.Q.Multiply(privKey.D).Normalize();
            if (q.IsInfinity)
            {
                throw new InvalidOperationException("Infinity is not a valid agreement value for ECDH");
            }
            var pubkey = ECKey.Secp256k1.Curve.CreatePoint(q.XCoord.ToBigInteger(), q.YCoord.ToBigInteger());
            pubkey = pubkey.Normalize();
            return(new ECKey(pubkey.GetEncoded(true), false).GetPubKey(true));
#endif
        }