//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); }
//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); }
//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("验证失败!"); } }
//生成RSA密钥对 private void btnGetKey_Click(object sender, EventArgs e) { string[] sKeys = RSACrypt.GenerateKeys(); txtPrivateKey.Text = sKeys[0]; txtPublicKey.Text = sKeys[1]; }