/// <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(); }
public void CombinedCryptoToolTest(string message, string password, bool aes, bool tdes, bool hum) { TestContext.WriteLine($"Params| message = {message}, password = {password}"); var sm = new SecurityModel() { SelectedAES = aes, SelectedTripleDES = tdes, SelectedHumbleCrypt = hum }; var cryptoTools = CryptoManager.BuildCryptoToolsFromSecurityModel(sm); var originalMessage = message; var encrypted = CryptoManager.RunSelectedEncryption(cryptoTools, message, password); var decrypted = CryptoManager.RunSelectedDecryption(cryptoTools, encrypted, password); TestContext.WriteLine($"Encrypted message = {encrypted}"); TestContext.WriteLine($"Has at least one CryptoToolSelect = {aes | tdes | hum}"); if (aes | tdes | hum) { Assert.AreNotEqual(encrypted, decrypted); } Assert.AreEqual(originalMessage, decrypted); }
/// <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); }