// TODO Make values dependent on settings private async void Encrypt_Click(object sender, RoutedEventArgs e) { EncryptLoadingGif.Visibility = Visibility.Visible; // Create a random salt and iv var salt = new byte[16]; var iv = new byte[16]; var rng = new RNGCryptoServiceProvider(); rng.GetBytes(salt); rng.GetBytes(iv); // Pre declaration of them for assigning during the secure string scope string filePath = FileTextBox.Text; if (!File.Exists(filePath)) { EncryptOutput.Content = "File not valid"; return; } // Assign the values to the CryptographicInfo object var data = new AesCryptographicInfo { CryptoManager = typeof(TripleDesCryptoManager).AssemblyQualifiedName, Hmac = null, InstanceKeyCreator = new KeyCreator { root_HashAlgorithm = typeof(SCryptKeyDerive).AssemblyQualifiedName, PerformanceDerivative = _performanceDerivative.PerformanceDerivativeValue, salt = salt }, EncryptionModeInfo = new EncryptionModeInfo { InitializationVector = iv, KeySize = KeySize, BlockSize = 128, Mode = CipherMode.CBC } }; // Run the encryption in a separate thread and return control to the UI thread await Task.Run(() => EncryptDataWithHeader(data, EncryptPasswordBox.SecurePassword, filePath)); EncryptLoadingGif.Visibility = Visibility.Hidden; }
private async void Decrypt_Click(object sender, RoutedEventArgs e) { DecryptLoadingGif.Visibility = Visibility.Visible; // Create the object used to represent the header data var data = new AesCryptographicInfo(); // Get the path from the box string outFilePath = DecryptFileLocBox.Text; // Read the header await Task.Run(() => data = (AesCryptographicInfo)data.ReadHeaderFromFile(outFilePath)); // Decrypt the data await Task.Run(() => DecryptDataWithHeader(data, DecryptPasswordBox.SecurePassword, outFilePath)); DecryptLoadingGif.Visibility = Visibility.Hidden; }