我想寫一個代碼來使用公鑰加密文本並使用私鑰和密碼進行解密。如何使用打開文件對話框?
我不是很擅長編程語言,因爲我不是編程的學生。但對於我的迷你項目,我需要編寫一些關於加密的程序。
對於下面的代碼使用我的C盤中的文本文件使用公鑰進行編碼。 但我想使用openfiledialog來選擇文件,而不是手動指揮它(不太實際)
真的很感謝任何人都可以幫我編輯代碼。 P.S.我真的不知道如何將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方法。你沒有嘗試。 –
我與大衛,這是一個非常容易的話題谷歌。 – Gusdor