/// <summary> /// This method handles the encrypt asynchronus result /// when a file encryption is requested. /// </summary> /// <param name="ar">The current asynchronus result.</param> private void EncryptFile(IAsyncResult ar) { // Get the async state object. AsynchronousAdvancedTripleDES state = (AsynchronousAdvancedTripleDES)ar.AsyncState; bool encrypt = false; try { // End the encrypt async and set // the cross-thread result. encrypt = state.EndEncryptFile(ar); } catch (Exception ex) { _errorMessage = ex.Message; } SetEncrypting(encrypt); }
/// <summary> /// Cryto execute. /// </summary> /// <param name="decryptFile">The decrypt file.</param> /// <param name="encryptFile">The encrypt file.</param> private void CryptExecuteEx(string decryptFile, string encryptFile) { // Create a new async advanced cryptography // class, for file encryption. AsynchronousAdvancedTripleDES asyncCrypt = new AsynchronousAdvancedTripleDES(); // Set the execute stop button. ExecuteStopCrypt(); try { // If no decryption file set // then throw and exception. if (String.IsNullOrEmpty(txtDecryptedLocalFile.Text.Trim())) { throw new Exception("Decrypt local file not specified"); } // If no decryption file set // then throw and exception. if (String.IsNullOrEmpty(txtEncryptLocalFile.Text.Trim())) { throw new Exception("Encrypt local file not specified"); } // Get the cryptography operation. switch (_cryto) { case CryptographyType.Encrypt: // Encrypt the current file to the specified file. // If no password has been specified then encrypt // with no password. if (String.IsNullOrEmpty(txtCryptPassword.Text.Trim())) { asyncCrypt.BeginEncryptFile(txtDecryptedLocalFile.Text.Trim(), txtEncryptLocalFile.Text.Trim(), new AsyncCallback(EncryptFile), asyncCrypt); } else { // Encrypt with the password specified. asyncCrypt.BeginEncryptFile(txtDecryptedLocalFile.Text.Trim(), txtEncryptLocalFile.Text.Trim(), txtCryptPassword.Text.Trim(), new AsyncCallback(EncryptFile), asyncCrypt); } break; case CryptographyType.Decrypt: // Decrypt the current file to the specified file. // If no password has been specified then decrypt // with no password. if (String.IsNullOrEmpty(txtCryptPassword.Text.Trim())) { asyncCrypt.BeginDecryptFile(txtDecryptedLocalFile.Text.Trim(), txtEncryptLocalFile.Text.Trim(), new AsyncCallback(DecryptFile), asyncCrypt); } else { // Decrypt with the password specified. asyncCrypt.BeginDecryptFile(txtDecryptedLocalFile.Text.Trim(), txtEncryptLocalFile.Text.Trim(), txtCryptPassword.Text.Trim(), new AsyncCallback(DecryptFile), asyncCrypt); } break; } } catch (Exception ex) { // Set the execution stop controls. ExecuteStopCrypt(); // On error trigger the // error event handler. if (OnError != null) { OnError(this, new ClientCommandArgs("ERROR", ex.Message, 000)); } } }