Ejemplo n.º 1
0
        public static bool VerifySignature(string publicKeyHex, string message, string signature)
        {
            var byt       = Utils.HexToBytes(publicKeyHex);
            var publicKey = PublicKey.fromString(byt);

            return(Ecdsa.verify(message, Signature.fromBase64(signature), publicKey));
        }
Ejemplo n.º 2
0
        public static bool VerifySignature(string publicKeyHex, string message, string signature)
        {
            var @byte     = publicKeyHex.ConvertHexToByteArray();
            var publicKey = PublicKey.fromString(@byte);

            return(Ecdsa.verify(message, Signature.fromBase64(signature), publicKey));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Verify signed event webhook requests.
        /// </summary>
        /// <param name="publicKey">elliptic curve public key</param>
        /// <param name="payload">event payload in the request body</param>
        /// <param name="signature">value obtained from the 'X-Twilio-Email-Event-Webhook-Signature' header</param>
        /// <param name="timestamp">value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header</param>
        /// <returns>true or false if signature is valid</returns>
        public bool VerifySignature(PublicKey publicKey, string payload, string signature, string timestamp)
        {
            var timestampedPayload = timestamp + payload;
            var decodedSignature   = Signature.fromBase64(signature);

            return(Ecdsa.verify(timestampedPayload, decodedSignature, publicKey));
        }
Ejemplo n.º 4
0
        public void testVerifyRightMessage()
        {
            PrivateKey privateKey = new PrivateKey();
            PublicKey  publicKey  = privateKey.publicKey();
            string     message    = "This is the right message";
            Signature  signature  = Ecdsa.sign(message, privateKey);

            Assert.True(Ecdsa.verify(message, signature, publicKey));
        }
Ejemplo n.º 5
0
        public void testVerifyWrongMessage()
        {
            PrivateKey privateKey = new PrivateKey();
            PublicKey  publicKey  = privateKey.publicKey();
            string     message1   = "This is the right message";
            string     message2   = "This is the wrong message";
            Signature  signature  = Ecdsa.sign(message1, privateKey);

            Assert.False(Ecdsa.verify(message2, signature, publicKey));
        }
Ejemplo n.º 6
0
 public bool IsValid()
 {
     if (this.FromAddress is null)
     {
         return(true);
     }
     if (this.Signature is null)
     {
         throw new Exception("No signature is in this transaction");
     }
     return(Ecdsa.verify(this.CalculateHash(), this.Signature, this.FromAddress));
 }
Ejemplo n.º 7
0
        public void testAssign()
        {
            // Generated by: openssl ecparam -name secp256k1 -genkey -out privateKey.pem
            string     privateKeyPem = EllipticCurve.Utils.File.read("files/privateKey.pem");
            PrivateKey privateKey    = PrivateKey.fromPem(privateKeyPem);

            string message = EllipticCurve.Utils.File.read("files/message.txt");

            Signature signature = Ecdsa.sign(message, privateKey);

            PublicKey publicKey = privateKey.publicKey();

            Assert.True(Ecdsa.verify(message, signature, publicKey));
        }
Ejemplo n.º 8
0
        public void testVerifySignature()
        {
            // openssl ec -in privateKey.pem -pubout -out publicKey.pem
            string publicKeyPem = EllipticCurve.Utils.File.read("files/publicKey.pem");

            // openssl dgst -sha256 -sign privateKey.pem -out signature.binary message.txt
            byte[] signatureDer = EllipticCurve.Utils.File.readBytes("files/signatureDer.txt");

            string message = EllipticCurve.Utils.File.read("files/message.txt");

            PublicKey publicKey = PublicKey.fromPem(publicKeyPem);
            Signature signature = Signature.fromDer(signatureDer);

            Assert.True(Ecdsa.verify(message, signature, publicKey));
        }
Ejemplo n.º 9
0
        //method to evaluate if it is a valid transaction
        public bool IsValid()
        {
            //mining rewards, no from address listed
            if (this.FromAddress is null)
            {
                return(true);
            }

            //check for signature
            if (this.Signature is null)
            {
                throw new Exception("No Signature in this transaction");
            }
            return(Ecdsa.verify(this.CalculateHash(), this.Signature, this.FromAddress));
        }