/// <summary> /// Encrypt the text currently in the window. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void encryptCurrentWindowToolStripMenuItem_Click(object sender, EventArgs e) { try { keyForm popup = new keyForm(); popup.ShowDialog(); _currentSecurityModel = popup.getSecurityModel(); //build crypto tools based off user input _currentCryptoTools = CryptoManager.BuildCryptoToolsFromSecurityModel(_currentSecurityModel).ToList(); popup.Dispose(); } catch (Exception ex) { MessageBox.Show("Popup failed : " + ex); InitializeSecurityObjects(); return; } try { var encryptedText = CryptoManager.RunSelectedEncryption(_currentCryptoTools, NoteTextBox1.Text, _currentSecurityModel.Password); NoteTextBox1.Text = encryptedText; } catch (Exception ex) { MessageBox.Show(ex.Message); InitializeSecurityObjects(); return; } InitializeSecurityObjects(); }
/// <summary> /// Save With Pin/Password. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveEncrypt_Click(object sender, EventArgs e) { try { keyForm popup = new keyForm(); popup.ShowDialog(); _currentSecurityModel = popup.getSecurityModel(); //build crypto tools based off user input _currentCryptoTools = CryptoManager.BuildCryptoToolsFromSecurityModel(_currentSecurityModel).ToList(); popup.Dispose(); } catch (Exception ex) { MessageBox.Show("popup failed : " + ex); InitializeSecurityObjects(); return; } SaveFileDialog saveFileBrowser = new SaveFileDialog(); saveFileBrowser.ShowDialog(); string encryptedText = string.Empty; try { encryptedText = CryptoManager.RunSelectedEncryption(_currentCryptoTools, NoteTextBox1.Text, _currentSecurityModel.Password); } catch (Exception ex) { MessageBox.Show(ex.Message); InitializeSecurityObjects(); return; } try { WriteTextToFile(saveFileBrowser.FileName, encryptedText); } catch (Exception ex) { MessageBox.Show(ex.Message); } //now that the text has been done reset security state InitializeSecurityObjects(); SetCurrentFile(saveFileBrowser.FileName); }
/// <summary> /// Open With Pin/Password. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DecryptOpen_Click(object sender, EventArgs e) { //open a file browser OpenFileDialog openFileBrowser = new OpenFileDialog(); openFileBrowser.ShowDialog(); string fileText = string.Empty; try { fileText = GetFileContents(openFileBrowser.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); InitializeSecurityObjects(); return; } keyForm popup = new keyForm(); popup.ShowDialog(); _currentSecurityModel = popup.getSecurityModel(); //build crypto tools based off user input _currentCryptoTools = CryptoManager.BuildCryptoToolsFromSecurityModel(_currentSecurityModel).ToList(); popup.Dispose(); //use password to decrypt String decryptedText = CryptoManager.RunSelectedDecryption(_currentCryptoTools, fileText, _currentSecurityModel.Password); NoteTextBox1.Text = decryptedText; //now that the text has been done reset security state InitializeSecurityObjects(); SetCurrentFile(openFileBrowser.FileName); }