Example #1
0
        private static void DigitalSignatures()
        {
            var document = Encoding.UTF8.GetBytes("Document to Sign");

            byte[] hashedDocument;

            hashedDocument = HashData.ComputeHashSha256(document);

            var digitalSignature = new DigitalSignature();

            digitalSignature.AssignNewKey();

            var signature = digitalSignature.SignData(hashedDocument);
            var verified  = digitalSignature.VerifySignature(hashedDocument, signature);

            Console.WriteLine("Digital Signature Demonstration in .NET");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("   Original Text = " +
                              Encoding.Default.GetString(document));

            Console.WriteLine();
            Console.WriteLine("   Digital Signature = " +
                              Convert.ToBase64String(signature));

            Console.WriteLine();

            Console.WriteLine(verified
                ? "The digital signature has been correctly verified."
                : "The digital signature has NOT been correctly verified.");
        }
Example #2
0
        private void btnVerify_Click(object sender, EventArgs e)
        {
            var hashData  = Convert.FromBase64String(txtResult.Text);
            var signature = Convert.FromBase64String(txtSignature.Text);

            if (rsa.VerifySignature(hashData, signature))
            {
                MessageBox.Show("Message is verified!");
            }
            else
            {
                MessageBox.Show("Message not correct!");
            }
        }