Exemple #1
0
        /// <summary>
        /// Handles the Click event of the BT_EncryptDecrypt control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private async void BT_EncryptDecrypt_Click(object sender, EventArgs e)
        {
            if (!ValidateInputs())
            {
                return;
            }
            SetUIEncryptionInProgress();
            try
            {
                using (var sourceFileStream = OFD_SourceFile.OpenFile())
                {
                    using (var targetFileStream = SFD_TargetFile.OpenFile())
                    {
                        //using ICryptographyService.DecryptStreamAsync method only as the task is to use xor for encryption and decryption, but the ICryptographyService is designed more universaly
                        await _cryptographyService.DecryptStreamAsync(sourceFileStream, targetFileStream, TB_PassPhrase.Text, _progress);

                        await targetFileStream.FlushAsync();
                    }
                }
                MessageBox.Show(this, "Encryption / decryption finished");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, $"Failed to encrypt / decrypt file.\n\nMessage:{ex.Message}");
            }
            SetUIReady();
        }