/// <summary> /// execute the encrypt file menu item. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void encryptFileToolStripMenuItem_Click(object sender, EventArgs e) { // dialog to select the file to encrypt. OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Title = "Select File To Encrypt"; // dialog to select the output filename SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Title = "Save Encrypted File As.."; // dialog to request a seed value. SeedInputBox seedInput = new SeedInputBox(); // get the input filename if (openDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // get the seed value: if (seedInput.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // get the output file-name: if (saveDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // all parameters gathered, generate an anonymous method delegate // to run in another thread: ThreadStart task = delegate { try { // create the encrypted file. CAEncryption.CreateEncryptedFile( new System.IO.FileInfo(openDlg.FileName), saveDlg.FileName, seedInput.SeedValue ); // message box for completion. MessageBox.Show("File Encrypted"); // reset the progress bar. this.EasyInvoke(delegate { this.progressBar1.Value = 0; }); } catch (Exception ex1) { MessageBox.Show(ex1.Message); } }; // create and start the thread: Thread encryptThread = new Thread(task); encryptThread.Start(); } } } }
/// <summary> /// execute the decrypt file menu item. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void decryptFileToolStripMenuItem_Click(object sender, EventArgs e) { // dialog to select the encrypted file. OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Select Encrypted File"; // dialog to request the seed. SeedInputBox inputBox = new SeedInputBox(); // get the input file if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // get the seed; if (inputBox.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // create the anonymous task delegate: ThreadStart task = new ThreadStart(delegate { // decrypt the file; CAEncryption.DecryptFile(dlg.FileName, inputBox.SeedValue); // reset the progress bar. this.EasyInvoke(delegate { this.progressBar1.Value = 0; }); // show a completion message. MessageBox.Show("File Decrypted"); }); // run the decryption task in seperate thread. Thread decryptThread = new Thread(task); decryptThread.Start(); } } }