public partial class frmRSA : Form
{
byte[] encMsg;
RSAParameters publickey;
RSAParameters privatekey;
private void menuKeyGen_Click(object sender, EventArgs e)
{
// 384 bits to 16384 bits in increments of 8 bits
// Create Public & Private Key and store..
RSACryptoServiceProvider RSAC = new RSACryptoServiceProvider(392);
publickey = RSAC.ExportParameters(false);
privatekey = RSAC.ExportParameters(true);
}
private void menuItem_Enc_Click(object sender, EventArgs e)
{
RSACryptoServiceProvider rs = new RSACryptoServiceProvider();
rs.ImportParameters(publickey);
encMsg = rs.Encrypt(Encoding.ASCII.GetBytes(txttoEnc.Text), false);
txtEnc.Text = Encoding.ASCII.GetString(encMsg, 0, encMsg.Length);
}
private void menuItem_Decode_Click(object sender, EventArgs e)
{
byte[] decMsg;
RSACryptoServiceProvider rs = new RSACryptoServiceProvider();
rs.ImportParameters(privatekey);
decMsg = rs.Decrypt(encMsg, false);
txtDec.Text =Encoding.ASCII.GetString(decMsg, 0, decMsg.Length);
}
}
Comments