private void encryptFile_Button_Click(object sender, RoutedEventArgs e)
        {
            string inputFileError  = ValidateInputPath(inputFile_TextBox.Text);
            string outputFileError = validateOutputPath(outputFile_TextBox.Text);

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

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

            try
            {
                FileEncryption.targetUsers = recipientsListBox.Items.Cast <User>().ToList();
                FileEncryption.mode        = GetSelectedCipherMode();
                FileEncryption.keySize     = Int32.Parse(keySize_TextBox.Text);
                //FileEncryption.key = GetAnuBytes(FileEncryption.keySize >> 3);
                FileEncryption.bufferSize = 1 << 15;
                FileEncryption.blockSize  = Int32.Parse(blockSize_TextBox.Text);
                FileEncryption.iv         = GetAnuBytes(16);

                FileEncryption.InitializeEncryption(inputFile_TextBox.Text, outputFile_TextBox.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during decryption: " + ex);
            }
        }
Esempio n. 2
0
        public static void generateKeyPair(string publicKeyPath, string privateKeyPath, string privateKeyPassword)
        {
            using (var rsa = new RSACryptoServiceProvider(1024))
            {
                try
                {
                    File.WriteAllText(publicKeyPath, rsa.ToXmlString(false));


                    byte[] passwordHash = generateHash(privateKeyPassword);

                    //content to write = AES.ECB.encrypt(rsa.ToXmlString(true), passwordHash)
                    byte[] priv = FileEncryption.encryptPrivateKey(rsa.ToXmlString(true), passwordHash);
                    File.WriteAllBytes(privateKeyPath, priv);


                    //File.WriteAllText(privateKeyPath, rsa.ToXmlString(true));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
        }
        private void decryptionInputButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                decryptionInputFileBox.Text = openFileDialog.FileName;
                FileEncryption.loadPossibleRecipientsAndFileType(openFileDialog.FileName, decryptionRecipientsList, extension_Label);
            }
        }
Esempio n. 4
0
        public static Key loadPrivateKey(string path, string password)
        {
            byte[] encryptedContent = File.ReadAllBytes(path);
            byte[] passwordHash     = generateHash(password);

            // byte[] decryptedContent = AES.ECB.decrypt(encryptedContent, passwordHash);
            // return new Key(Encoding.UTF8.GetString(decryptedContent))
            string decryptedConten = FileEncryption.decryptPrivateKey(encryptedContent, passwordHash);

            //return new Key(File.ReadAllText(path));
            return(new FileEncryptionTool.RSA.Key(decryptedConten));
        }
        private void DecryptFile_Button_Click(object sender, RoutedEventArgs e)
        {
            string inputFileError  = ValidateInputPath(decryptionInputFileBox.Text);
            string outputFileError = validateOutputPath(decryptionOutputFileBox.Text);

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

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

            try
            {
                FileEncryption.bufferSize = 1 << 15;
                //FileEncryption.key = GetAnuBytes(32);


                User selectedUser = (User)decryptionRecipientsList.SelectedItem;
                if (selectedUser == null)
                {
                    MessageBox.Show("A user was not chosen");
                    return;
                }
                string password = decryptionPassword.Password;

                FileEncryption.InitializeDecryption(decryptionInputFileBox.Text, decryptionOutputFileBox.Text, selectedUser, password);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error encountered during decryption");
            }
        }