Esempio n. 1
0
        private void DecryptFile_Button_Click(object sender, RoutedEventArgs e)
        {
            var inputFilePath  = decryptionInputFileBox.Text;
            var fileRootPath   = Path.GetDirectoryName(inputFilePath);
            var inputFileError = ValidateInputPath(inputFilePath);

            var extension = extension_Label.Content.ToString();

            var outputFileName = Path.Combine(fileRootPath, decryptionOutputFileBox.Text);

            try
            {
                if (!string.IsNullOrEmpty(Path.GetExtension(outputFileName)))
                {
                    throw new ArgumentException("You don't need to add file extension in the name - it's appended in the encrypted file. Provided extension will be overwritten.");
                }
            }
            catch (ArgumentException ex)
            {
                outputFileName  = Path.GetFileNameWithoutExtension(outputFileName);
                outputFileName += extension;
                outputFileName  = Path.Combine(fileRootPath, outputFileName);
                MessageBox.Show(ex.Message);
            }

            var outputFileError = ValidateOutputPath(outputFileName);

            if (inputFileError != null)
            {
                MessageBox.Show(inputFileError);
                return;
            }

            if (outputFileError != null)
            {
                MessageBox.Show(outputFileError);
                return;
            }

            try
            {
                FileEncryption.BufferSize = 1 << 22;


                var selectedUser = (User)decryptionRecipientsList.SelectedItem;
                if (selectedUser == null)
                {
                    MessageBox.Show("Please choose a user.");
                    return;
                }
                var password = decryptionPassword.Password;

                FileEncryption.InitializeDecryption(inputFilePath, outputFileName, selectedUser, password);
            }
            catch (Exception)
            {
                MessageBox.Show("Error encountered during decryption");
            }
        }
Esempio n. 2
0
        public static Key LoadPrivateKey(string path, string password)
        {
            var encryptedContent = File.ReadAllBytes(path);
            var passwordHash     = GenerateHash(password, true);
            var decryptedConten  = FileEncryption.DecryptPrivateKey(encryptedContent, passwordHash);

            return(new Key(decryptedConten));
        }
Esempio n. 3
0
        private void DecryptionInputButton_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                decryptionInputFileBox.Text = openFileDialog.FileName;
                FileEncryption.LoadPossibleRecipientsAndFileType(openFileDialog.FileName, decryptionRecipientsList, extension_Label);
            }
        }
Esempio n. 4
0
        public static void GenerateKeyPair(string publicKeyPath, string privateKeyPath, string privateKeyPassword)
        {
            using (var rsa = new RSACryptoServiceProvider(1024))
            {
                try
                {
                    File.WriteAllText(publicKeyPath, rsa.ToXmlString(false));
                    var passwordHash = GenerateHash(privateKeyPassword, true);

                    var priv = FileEncryption.EncryptPrivateKey(rsa.ToXmlString(true), passwordHash);
                    File.WriteAllBytes(privateKeyPath, priv);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
        }
Esempio n. 5
0
        private void EncryptFile_Button_Click(object sender, RoutedEventArgs e)
        {
            var inputFilePath  = inputFile_TextBox.Text;
            var fileRootPath   = Path.GetDirectoryName(inputFilePath);
            var inputFileError = ValidateInputPath(inputFilePath);

            var outputFileName  = Path.Combine(fileRootPath, outputFile_TextBox.Text);
            var outputFileError = ValidateOutputPath(outputFileName);

            if (inputFileError != null)
            {
                MessageBox.Show(inputFileError);
                return;
            }

            if (outputFileError != null)
            {
                MessageBox.Show(outputFileError);
                return;
            }

            try
            {
                FileEncryption.Users         = receiversListBox.Items.Cast <User>().ToList();
                FileEncryption.CipheringMode = GetSelectedCipherMode();
                FileEncryption.KeySize       = Int32.Parse(keySizeComboBox.Text);
                FileEncryption.BufferSize    = 1 << 22;
                //FileEncryption.FeedbackSize = Int32.Parse(feedbackSizeComboBox.Text);
                FileEncryption.IV = GetSaltBytes(8);

                FileEncryption.InitializeEncryption(inputFilePath, outputFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during decryption: " + ex);
            }
        }