From 740cdcf385ad93ef201de5fd9427fe7a26245fab Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 6 Dec 2018 15:24:12 +0200 Subject: [PATCH] Code cleaned up --- Crypto Notepad/Form1.cs | 34 +++++++++++++++++----------------- Crypto Notepad/SettingsForm.cs | 5 ++--- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Crypto Notepad/Form1.cs b/Crypto Notepad/Form1.cs index 38796d4..5402fc9 100644 --- a/Crypto Notepad/Form1.cs +++ b/Crypto Notepad/Form1.cs @@ -6,7 +6,6 @@ using System.IO; using System.Linq; using System.Net; -using System.Net.NetworkInformation; using System.Reflection; using System.Security.Cryptography; using System.Threading; @@ -50,6 +49,7 @@ void DecryptAES() { string opnfile = File.ReadAllText(OpenFile.FileName); string NameWithotPath = Path.GetFileName(OpenFile.FileName); + string de = AES.Decrypt(opnfile, publicVar.encryptionKey.Get(), ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize); customRTB.Text = de; @@ -927,24 +927,26 @@ void AutoLock(bool minimize) customRTB.SelectionStart = caretPos; this.Show(); } - catch (CryptographicException) + catch (Exception ex) { - DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); - if (dialogResult == DialogResult.Retry) + if (ex is CryptographicException) { - AutoLock(false); - } - if (dialogResult == DialogResult.Cancel) - { - publicVar.encryptionKey.Set(null); - customRTB.Clear(); - this.Text = appName.Remove(14); - OpenFile.FileName = ""; - this.Show(); - return; + DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); + if (dialogResult == DialogResult.Retry) + { + AutoLock(false); + } + if (dialogResult == DialogResult.Cancel) + { + publicVar.encryptionKey.Set(null); + customRTB.Clear(); + this.Text = appName.Remove(14); + OpenFile.FileName = ""; + this.Show(); + return; + } } } - } protected override void WndProc(ref Message m) @@ -1044,7 +1046,6 @@ private void customRTB_DragDrop(object sender, DragEventArgs e) currentFilename = Path.GetFileName(OpenFile.FileName); } } - } } @@ -1127,6 +1128,5 @@ private void customRTB_KeyUp(object sender, KeyEventArgs e) shiftPresed = false; } } - } } \ No newline at end of file diff --git a/Crypto Notepad/SettingsForm.cs b/Crypto Notepad/SettingsForm.cs index 218fe4a..7d429ad 100644 --- a/Crypto Notepad/SettingsForm.cs +++ b/Crypto Notepad/SettingsForm.cs @@ -18,7 +18,7 @@ private void SettingsForm_Load(object sender, EventArgs e) { foreach (FontFamily fonts in FontFamily.Families) { - comboBox1.Items.Add(fonts.Name); + comboBox1.Items.Add(fonts.Name); } comboBox1.Text = ps.RichTextFont; @@ -78,7 +78,6 @@ private void SetSettings(string value) ps.AutoLock = checkBox4.Checked; ps.AutoSave = checkBox5.Checked; ps.Save(); - publicVar.settingsChanged = true; this.Hide(); @@ -116,7 +115,7 @@ public static void AssociateExtension(string applicationExecutablePath, string e catch (Exception) { - } + } } public static void DissociateExtension(string applicationExecutablePath, string extension)