private async void Encrypt() { if (!ValidateInputFilePathAndPassword(EncryptInputFile)) { return; } _progress = 0; _token = new EasyCrypto.ReportAndCancellationToken(); SetProgressHandler(); OperationInProgress = true; try { await EasyCrypto.AesFileEncrytion.EncryptWithPasswordAsync( EncryptInputFile, EncryptOutputFile, Password, true, _token); if (_token.IsCanceled) { MessageBox.Show("Canceled"); } else { MessageBox.Show("Completed"); } } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex); ResetProgress(); } finally { ResetProgress(); } }
private async void Decrypt() { if (!ValidateInputFilePathAndPassword(DecryptInputFile)) { return; } EasyCrypto.ValidationResult validationResult; using (Stream s = new FileStream(DecryptInputFile, FileMode.Open)) { validationResult = EasyCrypto.AesEncryption.ValidateEncryptedDataWithPassword(s, Password); } if (!validationResult.IsValid) { if (!validationResult.KeyIsValid) { MessageBox.Show("Password is not valid."); } else { MessageBox.Show(validationResult.ErrorMessage); } return; } _progress = 0; _token = new EasyCrypto.ReportAndCancellationToken(); SetProgressHandler(); OperationInProgress = true; try { await EasyCrypto.AesFileEncrytion.DecryptWithPasswordAsync( DecryptInputFile, DecryptOutputFile, Password, true, _token); if (_token.IsCanceled) { MessageBox.Show("Canceled"); } else { MessageBox.Show("Completed"); } } catch (Exception ex) { MessageBox.Show("Error occurred: " + ex); ResetProgress(); } finally { ResetProgress(); } }