private async void button2_Click(object sender, EventArgs e) {//decrypt if (_mIsProcessRun) { MessageBox.Show("Process is run!"); return; } string cryptedFilePath = textBox1.Text; //source string plainFilePath = textBox2.Text; //dest string password = textBox3.Text; try { if (plainFilePath.Equals("")) { throw new Exception("Encrypted file path not inputed! Please input path"); } if (cryptedFilePath.Equals("")) { throw new Exception("Decrypted file path not inputed! Please input path"); } if (password.Equals("")) { throw new Exception("Password not inputed! Please input password"); } InputAlgoData(); await Task.Factory.StartNew(() => { try { _mIsProcessRun = true; MyRc5 crypter = MyRc5.GetRc5(_mWordLength, password, _keyLength, _numberOfRounds); crypter.OnDecryptedPasswordFailed += CrypterOnOnDecryptedPasswordFailed; crypter.OnProgressChanged += CrypterOnOnProgressChanged; crypter.OnProcessEnded += CrypterOnOnProcessEnded; crypter.Decrypt(cryptedFilePath, plainFilePath); _mIsProcessRun = false; MessageBox.Show("Decription complete"); } catch (Exception) { _mIsProcessRun = false; MessageBox.Show("Some error with Decription"); } }); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async void button8_Click(object sender, EventArgs e) { //decrypt if (_isProcessRun) { MessageBox.Show("Process is run!"); return; } string cryptedFilePath = textBox7.Text; //source string plainFilePath = textBox6.Text; //dest string password = textBox3.Text; try { if (plainFilePath.Equals("")) { throw new Exception("Encrypted file path not inputed! Please input path"); } if (cryptedFilePath.Equals("")) { throw new Exception("Decrypted file path not inputed! Please input path"); } if (password.Equals("")) { throw new Exception("Password not inputed! Please input password"); } await Task.Factory.StartNew(() => { try { _isProcessRun = true; Stopwatch sw = new Stopwatch(); sw.Start(); MyRc5 crypter = MyRc5.GetRc5(64, password, 16, 16); crypter.OnDecryptedPasswordFailed += CrypterOnOnDecryptedPasswordFailed; crypter.OnProgressChanged += CrypterOnOnProgressChanged; crypter.OnProcessEnded += CrypterOnOnProcessEnded; crypter.Decrypt(cryptedFilePath, plainFilePath); sw.Stop(); label1.Invoke((MethodInvoker) delegate { label1.Text = String.Format("rc5 time = {0}ms (decryption)", sw.ElapsedMilliseconds); }); _isProcessRun = false; MessageBox.Show("Decription complete"); } catch (Exception) { _isProcessRun = false; MessageBox.Show("Some error with Decription"); } }); } catch (Exception ex) { _isProcessRun = false; MessageBox.Show(ex.Message); } }