Exemplo n.º 1
0
        private void btnEncrypt_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;
            Bitmap result;

            if (sfdFile.ShowDialog() == DialogResult.OK)
            {
                string fileName = sfdFile.FileName;
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        string hiddenText = AESEncryption.Encrypt(tbFromText.Text, tbPassword.Text, tbIV.Text);
                        ControlEnable(this.Controls, false);
                        fileSize = bitmap.Height;
                        result   = SteganographyConvert.Encrypt(hiddenText, (Bitmap)bitmap.Clone());

                        switch (sfdFile.FilterIndex)
                        {
                        case 0: result.Save(fileName, ImageFormat.Png); break;

                        case 1: result.Save(fileName, ImageFormat.Bmp); break;

                        case 2: result.Save(fileName, ImageFormat.Jpeg); break;
                        }
                        this.Invoke(new Action(() => WarningNotice.Save()));
                    }
                    catch (SteganographySizeException ex)
                    {
                        this.Invoke(new Action(() => WarningNotice.CantConvertImage()));
                    }
                    finally
                    {
                        ControlEnable(this.Controls, true);
                    }
                });
            }
            sfdFile.FileName = "";
        }
Exemplo n.º 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);
            });
        }