Пример #1
0
        private void wndMain_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (files.Length > 1)
                {
                    MessageBox.Show(this, "Only single file is supported",
                                    "GO Encryptor",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    if (Path.GetExtension(files[0]) == ".genc")
                    {
                        var inputFile  = files[0];
                        var outputFile = Path.Combine(Path.GetDirectoryName(inputFile),
                                                      Path.GetFileNameWithoutExtension(inputFile));

                        string password = null;

                        if (EncryptionSdkWrapper.is_file_encrypted_with_password(inputFile) == 1)
                        {
                            var passwordWindow = new PasswordWindow();
                            passwordWindow.Owner = this;

                            passwordWindow.ShowDialog();
                            if (passwordWindow.DialogResult.Value)
                            {
                                password = passwordWindow.Password;
                            }
                            else
                            {
                                return;
                            }
                        }
                        else if (EncryptionSdkWrapper.is_file_encrypted(inputFile) == 0)
                        {
                            MessageBox.Show(this, "Not a valid GO encrypted file",
                                            "GO Encryptor",
                                            MessageBoxButton.OK, MessageBoxImage.Error);

                            return;
                        }

                        var loadingWindow = new LoadingWindow();
                        loadingWindow.Owner       = this;
                        loadingWindow.ShouldClose = false;
                        loadingWindow.ContentText = "Decrypting File...";

                        Thread thread = new Thread(() => DecryptFile(loadingWindow, inputFile, outputFile, password));
                        thread.Start();

                        if (!loadingWindow.ShouldClose)
                        {
                            loadingWindow.ShowDialog();
                        }

                        thread.Join();

                        if (success)
                        {
                            MessageBox.Show(this, "Successfully decrypted file: " + inputFile,
                                            "GO Encryptor",
                                            MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show(this, "Unable to decrypt file: " + error.ToString(),
                                            "GO Encryptor",
                                            MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        var inputFile  = files[0];
                        var outputFile = inputFile + ".genc";

                        var optionsWindow = new EncryptOptionWindow();
                        optionsWindow.Owner = this;

                        optionsWindow.ShowDialog();
                        if (optionsWindow.DialogResult.Value == true)
                        {
                            string password = optionsWindow.AuthorizedUsers ? null :
                                              optionsWindow.Password;

                            var loadingWindow = new LoadingWindow();
                            loadingWindow.Owner       = this;
                            loadingWindow.ShouldClose = false;
                            loadingWindow.ContentText = "Encrypting File...";

                            Thread thread = new Thread(() => EncryptFile(loadingWindow, inputFile, outputFile, password));
                            thread.Start();

                            if (!loadingWindow.ShouldClose)
                            {
                                loadingWindow.ShowDialog();
                            }

                            thread.Join();

                            if (success)
                            {
                                MessageBox.Show(this, "Successfully encrypted file: " + inputFile,
                                                "GO Encryptor",
                                                MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                            else
                            {
                                MessageBox.Show(this, "Unable to encrypt file: " + error.ToString(),
                                                "GO Encryptor",
                                                MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void Decrypt_Click(object sender, RoutedEventArgs e)
        {
            var fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = false;
            fileDialog.Filter      = "GO encrypted files (*.genc)| *.genc";

            if (fileDialog.ShowDialog() == true)
            {
                var inputFile  = fileDialog.FileName;
                var outputFile = "";

                if (Path.GetExtension(inputFile) != ".genc")
                {
                    MessageBox.Show(this, "Invalid GO encrypted file extension",
                                    "GO Encryptor",
                                    MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }
                else
                {
                    outputFile = Path.Combine(Path.GetDirectoryName(inputFile),
                                              Path.GetFileNameWithoutExtension(inputFile));
                }

                string password = null;

                if (EncryptionSdkWrapper.is_file_encrypted_with_password(inputFile) == 1)
                {
                    var passwordWindow = new PasswordWindow();
                    passwordWindow.Owner = this;

                    passwordWindow.ShowDialog();
                    if (passwordWindow.DialogResult.Value)
                    {
                        password = passwordWindow.Password;
                    }
                    else
                    {
                        return;
                    }
                }
                else if (EncryptionSdkWrapper.is_file_encrypted(inputFile) == 0)
                {
                    MessageBox.Show(this, "Not a valid GO encrypted file",
                                    "GO Encryptor",
                                    MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                var loadingWindow = new LoadingWindow();
                loadingWindow.Owner       = this;
                loadingWindow.ShouldClose = false;
                loadingWindow.ContentText = "Decrypting File...";

                Thread thread = new Thread(() => DecryptFile(loadingWindow, inputFile, outputFile, password));
                thread.Start();

                if (!loadingWindow.ShouldClose)
                {
                    loadingWindow.ShowDialog();
                }

                thread.Join();

                if (success)
                {
                    MessageBox.Show(this, "Successfully decrypted file: " + inputFile,
                                    "GO Encryptor",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show(this, "Unable to decrypt file: " + error.ToString(),
                                    "GO Encryptor",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }