private void btnEncTxt_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在加密..."; string rText = ""; if (radioKeyMode1.Checked) { rText = Enc.encryptAESData(tempAESKeyFile, txtText.Text, false, txtSecMode.Text); } else { rText = Enc.encryptData(tempPublicKeyFile, txtText.Text); } if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "加密操作失败"; MessageBox.Show(Enc.getErrorOnce(), "加密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "加密完成"; if (checkBase64.Checked) { byte[] rTextB64 = Encoding.Default.GetBytes(rText); rText = Convert.ToBase64String(rTextB64); } txtText.Text = rText; tabControl1.SelectedIndex = 3; } }
private void btnNewAES_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在创建对称密钥..."; string rText = Enc.getAESkey(int.Parse(txtAESKeyLength.Text)); if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "创建对称密钥失败"; MessageBox.Show(Enc.getErrorOnce(), "创建对称密钥失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "创建对称密钥完成。"; txtAES.Text = rText; tabControl1.SelectedIndex = 2; } }
private void btnNewPubKey_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在提取公钥..."; string rText = Enc.getPublicKey(txtPrivatePEM.Text); tabControl1.SelectedIndex = 1; if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "提取公钥操作失败"; MessageBox.Show(Enc.getErrorOnce(), "提取公钥操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "提取公钥完成。"; txtPublicPEM.Text = rText; } }
private void btnNewPriKey_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在创建私钥..."; string rText = Enc.genPrivateKey(int.Parse(txtKeyLength.Text)); tabControl1.SelectedIndex = 0; if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "创建私钥操作失败"; MessageBox.Show(Enc.getErrorOnce(), "创建私钥操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "创建私钥完成。"; txtPrivatePEM.Text = rText; } }
private void btnDecTxt_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在解密..."; string rText = txtText.Text; if (checkBase64.Checked) { try { byte[] rTextB64 = Convert.FromBase64String(rText); rText = Encoding.Default.GetString(rTextB64); } catch (Exception err) { toolStripStatusLabel1.Text = err.Message; MessageBox.Show(toolStripStatusLabel1.Text, "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (radioKeyMode1.Checked) { rText = Enc.decryptionAESData(tempAESKeyFile, rText); } else { rText = Enc.decryptionData(tempPrivateKeyFile, rText); } if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "解密操作失败"; MessageBox.Show(Enc.getErrorOnce(), "解密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "解密完成"; txtText.Text = rText; tabControl1.SelectedIndex = 3; } }
private void btnDecFile_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在解密..."; string rText = ""; if (radioKeyMode1.Checked) { rText = Enc.decryptionAESData(tempAESKeyFile, txtFrom.Text, true, "aes-256-cbc", txtTo.Text); } else { rText = Enc.decryptionData(tempPrivateKeyFile, txtFrom.Text, true, txtTo.Text); } if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "解密操作失败"; MessageBox.Show(Enc.getErrorOnce(), "解密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "解密完成"; } }
private void btnEncFile_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "正在加密..."; string rText = ""; if (radioKeyMode1.Checked) { rText = Enc.encryptAESData(tempAESKeyFile, txtFrom.Text, true, txtSecMode.Text, txtTo.Text); } else { rText = Enc.encryptData(tempPublicKeyFile, txtFrom.Text, true, txtTo.Text); } if (rText.Length == 0 && Enc.isErrorInfo()) { toolStripStatusLabel1.Text = "加密操作失败"; MessageBox.Show(Enc.getErrorOnce(), "加密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { toolStripStatusLabel1.Text = "加密完成"; } }