Exemplo n.º 1
0
        public static byte[] Sign(byte[] bytes, BigInteger secret)
        {
            EcdsaSignature sig = CreateEcdsaSignature(bytes, secret);

            byte[] der = sig.EncodeToDer();
            if (!IsStrictlyCanonical(der))
            {
                throw new InvalidOperationException("Signature is not strictly canonical.");
            }

            return(der);
        }
Exemplo n.º 2
0
        public static bool Verify(byte[] data, byte[] sigBytes, BigInteger pub)
        {
            EcdsaSignature signature  = EcdsaSignature.DecodeFromDer(sigBytes);
            var            signer     = new ECDsaSigner();
            ECPoint        pubPoint   = Secp256K1.Curve().DecodePoint(pub.ToByteArray());
            var            parameters = new ECPublicKeyParameters(pubPoint, Secp256K1.Params());

            signer.Init(false, parameters);
            try
            {
                return(signer.VerifySignature(data, signature.R, signature.S));
            }
            catch (Exception)
            {
                return(false);
            }
        }