private void btnDecrypt_Click(object sender, RoutedEventArgs e) { var key = priKeyList.SelectedItem as KeyId; if (key == null) { priKeyList.Focus(); priKeyList.IsDropDownOpen = true; } else { var pp = passphrase.SecurePassword; if (pp.Length == 0) { passphrase.Focus(); } else { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Choose file to decrypt"; ofd.Multiselect = false; ofd.Filter = "All files|*.*"; if (ofd.ShowDialog(this).GetValueOrDefault()) { var srcFile = ofd.FileName; var outFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(srcFile), System.IO.Path.GetFileNameWithoutExtension(srcFile) + ".decrypted" + System.IO.Path.GetExtension(srcFile)); if (File.Exists(outFile)) { if (MessageBox.Show("Decrypted file already exists, overwrite?", "Overwrite Confirmation", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } } var encryptArg = new FileDataInput { InputFile = srcFile, OutputFile = outFile, Operation = DataOperation.Decrypt, Passphrase = pp }; try { _tool.ProcessData(encryptArg); SelectFileInExplorer(outFile); } catch (Exception ex) { MessageBox.Show("Failed to decrypt: " + ex.Message); } } } } }
private void btnEncrypt_Click(object sender, RoutedEventArgs e) { var key = pubKeyList.SelectedItem as KeyId; if (key == null) { pubKeyList.Focus(); pubKeyList.IsDropDownOpen = true; } else { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Choose file to encrypt"; ofd.Multiselect = false; ofd.Filter = "All files|*.*"; if (ofd.ShowDialog(this).GetValueOrDefault()) { var srcFile = ofd.FileName; var outFile = srcFile + ".encrypted.txt"; var encryptArg = new FileDataInput { Armor = true, InputFile = srcFile, OutputFile = outFile, Operation = DataOperation.Encrypt, Recipient = key.Id, }; try { _tool.ProcessData(encryptArg); SelectFileInExplorer(outFile); } catch (Exception ex) { MessageBox.Show("Failed to encrypt: " + ex.Message); } } } }