Example #1
0
 //RSA加密
 private void btnEncrypt_Click(object sender, EventArgs e)
 {
     if (txtPrivateKey.Text.Trim() == "" || txtPublicKey.Text.Trim() == "")
     {
         MessageBox.Show("请先生成RSA密钥对!");
         return;
     }
     txtCiphertext.Text = RSACrypt.EncryptString(txtPlaintext.Text, txtPublicKey.Text);
 }
Example #2
0
        //RSA生成签名
        private void btnGetSign_Click(object sender, EventArgs e)
        {
            if (txtPrivateKey.Text.Trim() == "" || txtPublicKey.Text.Trim() == "")
            {
                MessageBox.Show("请先生成RSA密钥对!");
                return;
            }
            string hashCode = "";

            HashCode.GetHash(txtName.Text, ref hashCode);
            txtSigature.Text = RSACrypt.GetSign(hashCode, txtPrivateKey.Text);
        }
Example #3
0
        //RSA验证签名
        private void btnVerifySign_Click(object sender, EventArgs e)
        {
            if (txtPrivateKey.Text.Trim() == "" || txtPublicKey.Text.Trim() == "")
            {
                MessageBox.Show("请先生成RSA密钥对!");
                return;
            }
            string hashCode = "";

            HashCode.GetHash(txtName.Text, ref hashCode);
            bool bVerify = RSACrypt.VerifySign(hashCode, txtSigature.Text, txtPublicKey.Text);

            if (bVerify)
            {
                MessageBox.Show("验证通过!");
            }
            else
            {
                MessageBox.Show("验证失败!");
            }
        }
Example #4
0
 //生成RSA密钥对
 private void btnGetKey_Click(object sender, EventArgs e)
 {
     string[] sKeys = RSACrypt.GenerateKeys();
     txtPrivateKey.Text = sKeys[0];
     txtPublicKey.Text  = sKeys[1];
 }