public UserAccount()
        {
            CngKeyCreationParameters keyCreationParameters = new CngKeyCreationParameters();

            keyCreationParameters.ExportPolicy = CngExportPolicies.AllowPlaintextExport;
            keyCreationParameters.KeyUsage     = CngKeyUsages.Signing;

            CngKey key = CngKey.Create(CngAlgorithm.ECDsaP256, null, keyCreationParameters);



            ECDsaCng dsa = new ECDsaCng(key); //dsa = Digital Signature Algorithm

            byte[] privateKey = dsa.Key.Export(CngKeyBlobFormat.EccPrivateBlob);

            ECDSAPrivateKey = BitConverter.ToString(privateKey).Replace("-", String.Empty);



            //create public key
            byte[] publicKey = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob);

            ECSDAPublicKey = BitConverter.ToString(publicKey).Replace("-", String.Empty);



            //we calculate the hashvalue by slicing the end off of the public key
            string hashValue = ECDSAOperations.GetHashValue(publicKey);

            int hashLength = hashValue.Length;

            UserAddress = "0x" + hashValue.Substring(hashLength - ADDRESS_LENGTH);
        }
Example #2
0
        private void btnVerify_Click(object sender, EventArgs e)
        {
            string signature = txtMAC.Text;
            string publicKey = txtPublicKey.Text;
            string hashValue = txtHash.Text;


            bool verify = ECDSAOperations.VerifySignature(hashValue, signature, publicKey);
        }
Example #3
0
        private void btnSign_Click(object sender, EventArgs e)
        {
            string fileHash = ECDSAOperations.GetSha256FileHash(txtFileURL.Text);

            if (fileHash.Length > 0)
            {
                txtHash.Text = fileHash;

                string signature = ECDSAOperations.SignMessage(txtPrivateKey.Text, fileHash);
                txtMAC.Text = signature;
            }
        }