Example #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();
        }
Example #2
0
 /// <summary>
 /// Handles the Click event of the BT_SelectSourceFile 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 void BT_SelectSourceFile_Click(object sender, EventArgs e)
 {
     switch (OFD_SourceFile.ShowDialog(this))
     {
     case DialogResult.OK:
         L_SourceFile.Text = GetShortFileName(OFD_SourceFile.FileName);
         break;
     }
 }
Example #3
0
 /// <summary>
 /// Sets the UI into ready state.
 /// </summary>
 private void SetUIReady()
 {
     P_Inputs.Enabled  = true;
     L_SourceFile.Text = "";
     OFD_SourceFile.Reset();
     L_TargetFile.Text = "";
     SFD_TargetFile.Reset();
     P_Progress.Visible = false;
 }