private void btnProc_Click(object sender, EventArgs e) { if (lvwLoad.Items.Count < 1) { MessageBox.Show(Resources.MessageNoProcess, Resources.MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var crypt = new Cryptor(ProtectedData.Unprotect(Convert.FromBase64String(Settings.Default.tfbin), null, DataProtectionScope.CurrentUser)); var decryptFiles = lvwLoad.Items.Cast <ListViewItem>().Where(i => i.SubItems[1].Text == Resources.DecryptProperty).Select(_ => _.Text); var encryptFiles = lvwLoad.Items.Cast <ListViewItem>().Where(i => i.SubItems[1].Text == Resources.EncryptProperty).Select(_ => _.Text); if (decryptFiles.Any()) { var pf = new pinForm(Encoding.ASCII.GetString(ProtectedData.Unprotect(Convert.FromBase64String(Settings.Default.tfbin), null, DataProtectionScope.CurrentUser))); switch (pf.ShowDialog(this)) { case DialogResult.OK: break; case DialogResult.Abort: MessageBox.Show(Resources.MessageWrongPIN, Resources.MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; case DialogResult.Cancel: return; } foreach (var f in decryptFiles) { var plaintext = crypt.DecryptWithPassword(File.ReadAllBytes(f)); File.WriteAllBytes(f, plaintext); File.Move(f, f.Substring(0, f.LastIndexOf(".", StringComparison.Ordinal))); } } foreach (var f in encryptFiles) { var cipherText = crypt.EncryptWithPassword(File.ReadAllBytes(f)); File.WriteAllBytes(f, cipherText); File.Move(f, f + ".aesx"); } lvwLoad.Items.Clear(); }
private void btnDone_Click(object sender, EventArgs e) { var pf = new pinForm(accountCode); switch (pf.ShowDialog(this)) { case DialogResult.OK: var key = Encoding.ASCII.GetBytes(accountCode); Settings.Default.tfbin = Convert.ToBase64String(ProtectedData.Protect(key, null, DataProtectionScope.CurrentUser)); break; case DialogResult.Abort: MessageBox.Show(Resources.MessageWrongPIN, Resources.MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; case DialogResult.Cancel: return; } Close(); }
private void btnProc_Click(object sender, EventArgs e) { if (lvwLoad.Items.Count < 1) { MessageBox.Show(Resources.MessageNoProcess, Resources.MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var crypt = new Cryptor(ProtectedData.Unprotect(Convert.FromBase64String(Settings.Default.tfbin), null, DataProtectionScope.CurrentUser)); var decryptFiles = lvwLoad.Items.Cast<ListViewItem>().Where(i => i.SubItems[1].Text == Resources.DecryptProperty).Select(_ => _.Text); var encryptFiles = lvwLoad.Items.Cast<ListViewItem>().Where(i => i.SubItems[1].Text == Resources.EncryptProperty).Select(_ => _.Text); if (decryptFiles.Any()) { var pf = new pinForm(Encoding.ASCII.GetString(ProtectedData.Unprotect(Convert.FromBase64String(Settings.Default.tfbin), null, DataProtectionScope.CurrentUser))); switch (pf.ShowDialog(this)) { case DialogResult.OK: break; case DialogResult.Abort: MessageBox.Show(Resources.MessageWrongPIN, Resources.MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; case DialogResult.Cancel: return; } foreach (var f in decryptFiles) { var plaintext = crypt.DecryptWithPassword(File.ReadAllBytes(f)); File.WriteAllBytes(f, plaintext); File.Move(f, f.Substring(0, f.LastIndexOf(".", StringComparison.Ordinal))); } } foreach (var f in encryptFiles) { var cipherText = crypt.EncryptWithPassword(File.ReadAllBytes(f)); File.WriteAllBytes(f, cipherText); File.Move(f, f + ".aesx"); } lvwLoad.Items.Clear(); }