private async void Cypher_Click(object sender, RoutedEventArgs e) { try { string errors = ""; if (inputPath == "") { errors += "No input file specified\n"; } if (outputPath == "") { errors += "No output file specified\n"; } if (aes.cipherMode == 0) { errors += "No cipher mode specified\n"; } if (pendingRecipents == null || pendingRecipents.Count == 0) { errors += "No Recipient was assigned\n"; } if (errors != "") { MessageBox.Show(errors, "Error", MessageBoxButton.OK); return; } //INITIALIZE FileInfo info = new FileInfo(Path.GetTempFileName()); int randomValue; byte[] buffer = new byte[4]; random.NextBytes(buffer); randomValue = BitConverter.ToInt32(buffer, 0); string basePassword = String.Format("{0}{1}", DateTime.Now, randomValue); byte[] salt1 = new byte[8]; using (RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider()) { // Fill the array with a random value. rngCsp.GetBytes(salt1); } const int Iterations = 400; var keyGenerator = new Rfc2898DeriveBytes(basePassword, salt1, Iterations); aes.key = keyGenerator.GetBytes(aes.keySize); keyGenerator = new Rfc2898DeriveBytes(basePassword.Reverse().ToString(), salt1, Iterations); buffer = new byte[16]; random.NextBytes(buffer); aes.iV = buffer; // END OF INITIALIZE foreach (string nickname in pendingRecipents) { aes.addUser(nickname); } using (var output = File.Open(outputPath, FileMode.Create)) { using (var xmlOutput = XmlWriter.Create(output)) { xmlOutput.WriteStartDocument(); FilesManager.WriteToXml(xmlOutput, aes); xmlOutput.Flush(); xmlOutput.WriteEndDocument(); } using (var source = File.Open(inputPath, FileMode.Open)) { using (var sourceEncypted = aes.EncrypteStream(source)) { Task copyTask = sourceEncypted.CopyToAsync(output); //new Thread(() => StartUpdatingprogress(source, copyTask)).Start(); long length = source.Length; do { double position = (double)source.Position; pbStatus.Value = (position / length) * 100; }while (!copyTask.IsCompleted); pbStatus.Value = 100; await copyTask; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK); } }