c# rsa注冊完成加密文字。本站提示廣大學習愛好者:(c# rsa注冊完成加密文字)文章只能為提供參考,不一定能成為您想要的結果。以下是c# rsa注冊完成加密文字正文
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
private void btencoding_Click(object sender, EventArgs e)
{
if (mbox.Text == "")
{
MessageBox.Show("加密文字信息不克不及為空!");
return;
}
if (publickey.Text == "")
{
MessageBox.Show("請生成公鑰!");
return;
}
try
{
string pubKey = publickey.Text;
byte[] mw = ASCIIEncoding.ASCII.GetBytes(mbox.Text);
RSACryptoServiceProvider crypt = new RSACryptoServiceProvider();
crypt.FromXmlString(pubKey);
mw = crypt.Encrypt(mw, false);
string encryttext = Convert.ToBase64String(mw);//加密後的成果如何處置處理顯示亂碼成績
cbox.Text = encryttext;
}
catch
{
MessageBox.Show("請檢討能否翻開公匙或許公匙能否破壞!");
}
}
private void btdecoding_Click(object sender, EventArgs e)
{
if (cbox.Text == "")
{
MessageBox.Show("請生成密鑰!");
return;
}
try
{
RSACryptoServiceProvider crypt = new RSACryptoServiceProvider();
byte[] bytes = Convert.FromBase64String(cbox.Text);//從密文框中掏出的字符串准確處置能力解密
string prtKey = privatekey.Text;
crypt.FromXmlString(prtKey);
byte[] decryptbyte = crypt.Decrypt(bytes, false);
string decrypttext = Encoding.Default.GetString(decryptbyte);
mbox.Text = decrypttext;
}
catch (CryptographicException ex)
{
//MessageBox.Show("請檢討能否翻開私匙或許私匙能否破壞!");
MessageBox.Show(ex.ToString());
} if (cbox.Text == "")
{
MessageBox.Show("請生成密鑰!");
return;
}
}