RSA对刚才的加密密钥进行加密。
8.2算法程序
8.2.1 算法功能类代码
using System;
using System.Collections.Generic; using System.Linq; using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography; using System.IO; using System.Xml;
using System.Management; using Microsoft.Win32;
namespace mimaxue46.leiclass {
class RSA {
///
///
public string RSAEncrypt(string publickey, string content) {
publickey =
@\9z7SVju8s0X4gZ6AzZTn06jzWOgyPRV54Q4I0DCYadWW4Ze3e+BOtwgVU1Og3qHKn8vygoj40J6U85Z/PTJu3hN1m75Zr195ju7g9v4Hk=
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] cipherbytes;
rsa.FromXmlString(publickey);
cipherbytes = rsa.Encrypt(Encoding.UTF8.GetBytes(content), false);
return Convert.ToBase64String(cipherbytes); }
///
///
public string RSADecrypt(string privatekey, string content) {
privatekey =
@\9z7SVju8s0X4gZ6AzZTn06jzWOgyPRV54Q4I0DCYadWW4Ze3e+BOtwgVU1Og3qHKn8vygoj40J6U85Z/PTJu3hN1m75Zr195ju7g9v4Hk=
/hf2dnK7rNfl3lbqghWcpFdu778hUpIEBixCDL5WiBtpkZdpSw90aERmHJYaW2RGvGRi6zSftLh00KHsPcNUMw==
6Cn/jOLrPapDTEp1Fkq+uz++1Do0eeX7HYqi9rY29CqShzCeI7LEYOoSwYuAJ3xA/DuCdQENPSoJ9KFbO4Wsow==
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] cipherbytes;
rsa.FromXmlString(privatekey);
35
cipherbytes = rsa.Decrypt(Convert.FromBase64String(content), false);
return Encoding.UTF8.GetString(cipherbytes); } } }
8.2.2 算法窗体代码
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using mimaxue46.leiclass;
namespace mimaxue46.FormsClass {
public partial class RSA : Form {
public RSA() {
InitializeComponent(); }
mimaxue46.leiclass.RSA F = new leiclass.RSA();
private void button1_Click(object sender, EventArgs e) {
if (textBox2.Text == \ || textBox2.Text == null) {
MessageBox.Show(\请输入秘钥\); } else {
textBox3.Text = F.RSAEncrypt(textBox2.Text, textBox1.Text); } }
private void button3_Click(object sender, EventArgs e) {
textBox4.Text = textBox3.Text; }
private void button2_Click(object sender, EventArgs e) {
if (textBox6.Text == \ || textBox6.Text == null) {
MessageBox.Show(\请输入秘钥\); } else {
textBox5.Text = F.RSADecrypt(textBox6.Text, textBox4.Text); } }
private void RSA_Load(object sender, EventArgs e) {
36
} } }
8.3运行界面
37
9 PGP加密软件的应用
9.1软件介绍
PGP(Pretty Good Privacy),是一个基于RSA公钥加密体系的邮件加密软件。可以用它对邮
件保密以防止非授权者阅读,它还能对邮件加上数字签名从而使收信人可以确认邮件的发送者,并能确信邮件没有被篡改。它可以提供一种安全的通讯方式,而事先并不需要任何保密的渠道用来传递密匙。它采用了一种RSA和传统加密的杂合算法,用于数字签名的邮件文摘算法,加密前压缩等,还有一个良好的人机工程设计。它的功能强大,有很快的速度。而且它的源代码是免费的
9.2安装过程及主要界面
38
39