コード例 #1
0
        private async void button9_Click(object sender, EventArgs e)
        {
            //crypt
            if (_isProcessRun)
            {
                MessageBox.Show("Process is run!");
                return;
            }
            string plainFilePath   = textBox7.Text; //source
            string cryptedFilePath = textBox6.Text; //dest
            string password        = textBox3.Text;

            try
            {
                if (plainFilePath.Equals(""))
                {
                    throw new Exception("file path not inputed! Please input path");
                }
                if (cryptedFilePath.Equals(""))
                {
                    throw new Exception("Encrypted file path not inputed! Please output path");
                }
                if (password.Equals(""))
                {
                    throw new Exception("Password not inputed! Please input password");
                }
                await Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        _isProcessRun = true;
                        MyRc5 crypter = MyRc5.GetRc5(64, password, 16, 16);
                        crypter.OnDecryptedPasswordFailed += CrypterOnOnDecryptedPasswordFailed;
                        crypter.OnProgressChanged         += CrypterOnOnProgressChanged;
                        crypter.OnProcessEnded            += CrypterOnOnProcessEnded;
                        crypter.Encrypt(plainFilePath, cryptedFilePath);
                        _isProcessRun = false;
                        sw.Stop();
                        label1.Invoke((MethodInvoker) delegate
                        {
                            label1.Text = String.Format("rc5 time = {0}ms",
                                                        sw.ElapsedMilliseconds);
                        });
                        MessageBox.Show("Encryption complete");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Some error with encryption");
                    }
                });
            }
            catch (Exception ex)
            {
                _isProcessRun = false;
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        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);
            }
        }