Пример #1
0
        private void btnEncrypt_Click(object sender, RoutedEventArgs e)
        {
            var key = pubKeyList.SelectedItem as KeyId;

            if (key == null)
            {
                pubKeyList.Focus();
                pubKeyList.IsDropDownOpen = true;
            }
            else
            {
                var msg = new ChooseFileMessage(newFiles =>
                {
                    var srcFile = newFiles.First();
                    var outFile = srcFile + ".encrypted.txt";

                    var encryptArg = new FileDataInput
                    {
                        Armor = true,
                        AlwaysTrustPublicKey = trustPubKey.IsChecked.GetValueOrDefault(),
                        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);
                    }
                })
                {
                    Caption = "Choose file to encrypt",
                    Filters = "All files|*.*",
                    Purpose = FilePurpose.OpenSingle,
                };

                msg.HandleWithPlatform(this);
            }
        }
Пример #2
0
        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,
                        AlwaysTrustPublicKey = trustPubKey.IsChecked.GetValueOrDefault(),
                        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);
                    }
                }
            }
        }