Esempio n. 1
0
        } // End Function SignHashInternal

        // Abstract
        public override bool VerifyHash(byte[] hash, byte[] signature)
        {
            if (hash == null)
            {
                throw new System.ArgumentNullException(nameof(hash));
            }

            if (signature == null)
            {
                throw new System.ArgumentNullException(nameof(signature));
            }

            int num = 2 * AsymmetricAlgorithmHelpers.BitsToBytes(this.KeySize);

            if (signature.Length != num)
            {
                return(false);
            }

            byte[] derSignature = AsymmetricAlgorithmHelpers.ConvertIeee1363ToDer(signature);

            Org.BouncyCastle.Crypto.Signers.ECDsaSigner signer =
                new Org.BouncyCastle.Crypto.Signers.ECDsaSigner();
            signer.Init(false, this.m_pubKey);

            Org.BouncyCastle.Math.BigInteger[] bigIntegerArray = this.DerDecode(derSignature);
            return(signer.VerifySignature(hash, bigIntegerArray[0], bigIntegerArray[1]));
        } // End Function VerifyHash
Esempio n. 2
0
        internal Secp256k1PublicKey(Org.BouncyCastle.Asn1.X9.X9ECParameters k1Params, Org.BouncyCastle.Math.EC.ECPoint publicKey)
        {
            this.publicKey = publicKey;
            this.signer    = new Org.BouncyCastle.Crypto.Signers.ECDsaSigner(
                new Org.BouncyCastle.Crypto.Signers.HMacDsaKCalculator(
                    new Org.BouncyCastle.Crypto.Digests.Sha256Digest()));
            var parameters = new Org.BouncyCastle.Crypto.Parameters.ECPublicKeyParameters(
                this.publicKey,
                new Org.BouncyCastle.Crypto.Parameters.ECDomainParameters(k1Params.Curve, k1Params.G, k1Params.N, k1Params.H));

            signer.Init(false, parameters);
        }
Esempio n. 3
0
        public Secp256k1PublicKey(ReadOnlySpan <byte> key)
        {
            var k1Params = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256k1");

            this.publicKey = k1Params.Curve.DecodePoint(key.ToArray());
            this.signer    = new Org.BouncyCastle.Crypto.Signers.ECDsaSigner(
                new Org.BouncyCastle.Crypto.Signers.HMacDsaKCalculator(
                    new Org.BouncyCastle.Crypto.Digests.Sha256Digest()));
            var parameters = new Org.BouncyCastle.Crypto.Parameters.ECPublicKeyParameters(
                this.publicKey,
                new Org.BouncyCastle.Crypto.Parameters.ECDomainParameters(k1Params.Curve, k1Params.G, k1Params.N, k1Params.H));

            signer.Init(false, parameters);
        }
Esempio n. 4
0
        public byte[] SignHashInternal(byte[] hash)
        {
            if (hash == null)
            {
                throw new System.ArgumentNullException(nameof(hash));
            }

            Org.BouncyCastle.Crypto.Signers.ECDsaSigner signer = new Org.BouncyCastle.Crypto.Signers.ECDsaSigner();
            signer.Init(true, this.m_privKey);

            Org.BouncyCastle.Math.BigInteger[] signature = signer.GenerateSignature(hash);
            byte[] encoded = this.DerEncode(signature[0], signature[1]);

            return(encoded);
        } // End Function SignHashInternal
Esempio n. 5
0
        internal Secp256k1KeyPair(Org.BouncyCastle.Math.BigInteger privateKey)
        {
            this.privateKey = privateKey;

            this.k1Params  = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256k1");
            this.publicKey = new Secp256k1PublicKey(k1Params, k1Params.G.Multiply(privateKey));

            signer = new Org.BouncyCastle.Crypto.Signers.ECDsaSigner(
                new Org.BouncyCastle.Crypto.Signers.HMacDsaKCalculator(
                    new Org.BouncyCastle.Crypto.Digests.Sha256Digest()));
            var parameters = new Org.BouncyCastle.Crypto.Parameters.ECPrivateKeyParameters(
                this.privateKey,
                new Org.BouncyCastle.Crypto.Parameters.ECDomainParameters(k1Params.Curve, k1Params.G, k1Params.N, k1Params.H));

            signer.Init(true, parameters);
        }