Ejemplo n.º 1
0
        public static string getSignature(string textToSign, string publicKey, string privateKey)
        {
            ECDsaSignature signer;

            signer = ECDsaSignature.FromKeys(publicKey, privateKey);
            byte[] byteStr       = Encoding.Default.GetBytes(textToSign);
            byte[] byteSignature = signer.SignData(byteStr);

            return(Encoding.Default.GetString(byteSignature));
        }
Ejemplo n.º 2
0
        public static bool CheckSignature(Input inp)
        {
            List <string> stringList        = inp.ScriptSign.Split(' ').ToList();
            string        signature         = stringList[0];
            string        receiverPublicKey = stringList[1];
            string        stringToVerify    = inp.PrevTransactionHash + " " + inp.OutputIndex.ToString();

            ECDsaSignature verifier = ECDsaSignature.FromKeys(receiverPublicKey);

            return(verifier.VerifyData(Encoding.Default.GetBytes(stringToVerify), Encoding.Default.GetBytes(signature)));
        }
Ejemplo n.º 3
0
        private void button_validate_Click(object sender, EventArgs e)
        {
            if (textBox_Verifier_PublicKey.Text == string.Empty || textBox_Verifier_Message.Text == string.Empty || textBox_verifier_signature.Text == string.Empty)
            {
                MessageBox.Show("Please check input parameters");
                return;
            }

            ///DATA SIGNATURE VERIFICATION-SERVER SIDE Parameters needed: Public Key, The Signature, The Message
            string publicKey = textBox_Verifier_PublicKey.Text;
            string message   = textBox_Verifier_Message.Text;

            byte[]         byteMessage   = Encoding.Default.GetBytes(message);
            byte[]         byteSignature = signature;
            ECDsaSignature verifier      = ECDsaSignature.FromKeys(publicKey);              //creating a verifier object
            bool           result        = verifier.VerifyData(byteMessage, byteSignature); //result if the signature was created by true public key

            MessageBox.Show(result?"the signature is valid":"signature is invalid");
        }
Ejemplo n.º 4
0
        private void button_sign_Click(object sender, EventArgs e)
        {
            if (textBox_prover_message.Text == string.Empty || textBox_prover_privateKey.Text == string.Empty || textBox_prover_message.Text == string.Empty)
            {
                MessageBox.Show("Please check input parameters");
                return;
            }

            ///DATA SIGNING OPERATION-CLIENT SIDE Parameters needed: Private Key, Public Key, the Message(to sign)
            string message    = textBox_prover_message.Text;                 //string(message object) to sign
            string privateKey = textBox_prover_privateKey.Text;              //private key generated by KeyGen
            string publicKey  = textBox_prover_PublicKey.Text;               //public key generated by KeyGen

            signer = ECDsaSignature.FromKeys(publicKey, privateKey);         //creating signer object with public and private key parameters
            byte[] byteMessage   = Encoding.Default.GetBytes(message);       //converting the message object to byteArray to enable signing operation
            byte[] byteSignature = signer.SignData(byteMessage);             //signing operation with signer object
            signature = signer.SignData(byteMessage);
            string signatureStr = Encoding.Default.GetString(byteSignature); //converting signature from byteArray to string

            textBox_prover_signature.Text   = signatureStr;
            textBox_verifier_signature.Text = signatureStr;
        }