【发布时间】:2013-10-29 14:16:51
【问题描述】:
我正在尝试编写代码以使用公钥加密文本并使用私钥和密码进行解密。
我对编程语言不是很好,因为我不是编程学生。但是对于我的小项目,我需要编写一些关于加密的程序。
对于以下代码,使用我的 c 驱动器中的文本文件使用公钥进行编码。 但我想使用 openfiledialog 来选择文件而不是手动引导它(不是很实用)
如果有人可以帮助我编辑代码,我将不胜感激。 附:我真的不知道如何将 openfiledialog 应用于我的代码。当我使用来自 youtubes 和 google 的信息时,我不断收到错误消息。
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 System.IO;
using DidiSoft.Pgp;
namespace TEST2
{
public partial class Form1 : Form
{
PGPLib pgp = new PGPLib();
public Form1()
{
InitializeComponent();
}
private void encryptButton_Click(object sender, EventArgs e)
{
string testingstring = pgp.EncryptString(testTextBox.Text, new FileInfo(@"c:\TCkeyPublic.txt"));
encryptedtextTextBox.Text = testingstring;
}
private void decryptButton_Click(object sender, EventArgs e)
{
try
{
String plainString = pgp.DecryptString(encryptedtextTextBox.Text,
new FileInfo(@"c:\TCkeyPrivate.txt"), passphraseTextBox.Text);
decryptedtextTextBox.Text = plainString;
encryptedtextTextBox.Text = "";
passphraseTextBox.Text = "";
}
catch
{
MessageBox.Show("ERROR! Please check passphrase and do not attempt to edit cipher text");
}
}
private void passphraseTextBox_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
【问题讨论】:
-
创建一个
OpenFileDialog实例,并调用它的ShowDialog方法。你没有尝试。 -
我和大卫在一起,这对谷歌来说是一个非常容易的话题。
标签: c# winforms filedialog