예제 #1
0
        private void btnCheckResult_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbPath.Text))
            {
                WarningNotice.InputString();
                return;
            }
            if (!File.Exists(tbPath.Text))
            {
                WarningNotice.NotFound();
                return;
            }
            FileInfo file = new FileInfo(tbPath.Text);

            if (cbHMACMode.Checked)
            {
                Task.Factory.StartNew(() =>
                {
                    ControlEnable(this.Controls, false);
                    Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACRIPEMD160Encryption.Encrypt(file, tbHMACPassword.Text)));
                    task.Wait();
                    this.Invoke(new Action(() => tbResult.Text = task.Result));
                    this.Invoke(new Action(() => WarningNotice.Completed()));
                    ControlEnable(this.Controls, true);
                });
            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    ControlEnable(this.Controls, false);
                    Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => RIPEMD160Encryption.Encrypt(file)));
                    task.Wait();
                    this.Invoke(new Action(() => tbResult.Text = task.Result));
                    this.Invoke(new Action(() => WarningNotice.Completed()));
                    ControlEnable(this.Controls, true);
                });
            }
        }
예제 #2
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            if (pbImage.Image == null)
            {
                WarningNotice.NoImage();
                return;
            }
            if (tbPassword.Text.Length != 16 && tbPassword.Text.Length != 24 && tbPassword.Text.Length != 32)
            {
                WarningNotice.KeyLength(16, 24, 32);
                return;
            }
            if (tbIV.Text.Length != 16)
            {
                WarningNotice.IVLength(16);
                return;
            }
            Bitmap bitmap = (Bitmap)pbImage.Image;

            Task.Factory.StartNew(() =>
            {
                ControlEnable(this.Controls, false);
                fileSize          = bitmap.Height;
                string hiddenText = SteganographyConvert.Decrypt(bitmap);
                this.Invoke(new Action(() =>
                {
                    try
                    {
                        tbToText.Text = AESEncryption.Decrypt(hiddenText, tbPassword.Text, tbIV.Text);
                        WarningNotice.Completed();
                    }
                    catch (Exception)
                    {
                        this.Invoke(new Action(() => WarningNotice.WrongKey()));
                    }
                }));
                ControlEnable(this.Controls, true);
            });
        }
예제 #3
0
        private void btnCheckResult_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbPath.Text))
            {
                WarningNotice.InputString();
                return;
            }
            if (!File.Exists(tbPath.Text))
            {
                WarningNotice.NotFound();
                return;
            }
            FileInfo file = new FileInfo(tbPath.Text);

            Task.Factory.StartNew(() =>
            {
                switch (gbSHAMode.Controls.OfType <RadioButton>().FirstOrDefault(rb => rb.Checked))
                {
                case RadioButton rb1 when rb1.Name == rdbtnSHA1.Name:
                    if (cbHMACMode.Checked)
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA1Encryption.Encrypt(file, tbHMACPassword.Text)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    else
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA1Encryption.Encrypt(file)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    break;

                case RadioButton rb2 when rb2.Name == rdbtnSHA256.Name:
                    if (cbHMACMode.Checked)
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA256Encryption.Encrypt(file, tbHMACPassword.Text)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    else
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA256Encryption.Encrypt(file)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    break;

                case RadioButton rb3 when rb3.Name == rdbtnSHA384.Name:
                    if (cbHMACMode.Checked)
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA384Encryption.Encrypt(file, tbHMACPassword.Text)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    else
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA384Encryption.Encrypt(file)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    break;

                case RadioButton rb4 when rb4.Name == rdbtnSHA512.Name:
                    if (cbHMACMode.Checked)
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => HMACSHA512Encryption.Encrypt(file, tbHMACPassword.Text)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    else
                    {
                        ControlEnable(this.Controls, false);
                        Task <string> task = Task.Factory.StartNew <string>(new Func <string>(() => SHA512Encryption.Encrypt(file)));
                        task.Wait();
                        this.Invoke(new Action(() => tbResult.Text = task.Result));
                        this.Invoke(new Action(() => WarningNotice.Completed()));
                        ControlEnable(this.Controls, true);
                    }
                    break;
                }
            });
        }