//文件解密 private void btnFileDecode_Click(object sender, EventArgs e) { if (txtPrivateKey.Text.Trim() == "" || txtPublicKey.Text.Trim() == "") { MessageBox.Show("请先生成RSA密钥对!"); return; } if (txtPrivateKey.Text.Trim() == "" || txtPublicKey.Text.Trim() == "") { MessageBox.Show("请先生成RSA密钥对!"); return; } DialogResult dlgResult = openFileDlg.ShowDialog(); if (DialogResult.OK == dlgResult) { string srcFile = openFileDlg.FileName; int pos = srcFile.Replace("/", "\\").LastIndexOf("\\"); string path = srcFile.Substring(0, pos + 1); string name = srcFile.Substring(pos + 1); string destFile = path + "复本 " + name.Replace(".m", ""); FileCrypt.DecryptOther(srcFile, destFile, txtPrivateKey.Text); dlgResult = MessageBox.Show("解密成功!是否立即打开明文:复本 " + name.Replace(".m", "") + "?", "提示", MessageBoxButtons.YesNo); if (DialogResult.Yes == dlgResult) { Process.Start("explorer", "/select, " + destFile); } } }
//文件加密 private void btnFileEncode_Click(object sender, EventArgs e) { if (txtPrivateKey.Text.Trim() == "" || txtPublicKey.Text.Trim() == "") { MessageBox.Show("请先生成RSA密钥对!"); return; } DialogResult dlgResult = openFileDlg.ShowDialog(); if (DialogResult.OK == dlgResult) { string srcFile = openFileDlg.FileName; string destFile = srcFile + ".m"; FileCrypt.EncryptOther(srcFile, destFile, txtPublicKey.Text); dlgResult = MessageBox.Show("加密成功!是否立即打开密文:" + openFileDlg.SafeFileName + ".m?", "提示", MessageBoxButtons.YesNo); if (DialogResult.Yes == dlgResult) { Process.Start("explorer", "/select, " + destFile); } } }