Exemplo n.º 1
0
        private void Decryption_bt_Click(object sender, EventArgs e)
        {
            try
            {
                Bitmap img     = (Bitmap)ulr_image.BackgroundImage;
                string Steg_pw = "123";

                string extractString = SteganographyHelper.ExtractText(img);
                if (string.IsNullOrEmpty(Steg_pw))
                {
                    MessageBox.Show("Please specify the password, To Extract the information.", "Security");
                    return;
                }

                extractString = RijndaelAlgo.Decrypt(extractString, Steg_pw);
                string inputFile  = filepath.Text;
                string outpath    = Path.GetDirectoryName(filepath.Text) + Guid.NewGuid().ToString() + Path.GetExtension(filepath.Text);
                string outputFile = outpath;
                string password   = extractString; // Your Key Here

                UnicodeEncoding UE  = new UnicodeEncoding();
                byte[]          key = UE.GetBytes(password);

                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                                                   RMCrypto.CreateDecryptor(key, key),
                                                   CryptoStreamMode.Read);

                FileStream fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                {
                    fsOut.WriteByte((byte)data);
                }

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();
                File.Delete(filepath.Text);
                File.Move(outpath, filepath.Text);
                MessageBox.Show("File Decrypted successfully", "Information");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Decryption failed!  " + ex.Message, "Error");
                return;
            }
        }
Exemplo n.º 2
0
        private void Encryption_bt_Click(object sender, EventArgs e)
        {
            string embtext = pw_tx.Text;
            //  string password = @"myKey123"; // Your Key Here
            string password = pw_tx.Text; // Your Key Here

            UnicodeEncoding UE = new UnicodeEncoding();

            byte[] key     = UE.GetBytes(password);
            string outpath = Path.GetDirectoryName(filepath.Text) + Guid.NewGuid().ToString() + Path.GetExtension(filepath.Text);
            //   outputpath.Text = Path.GetExtension(fdlg.FileName);
            // outputpath.Text = Path.GetDirectoryName(fdlg.FileName);
            string     cryptFile = outpath;
            FileStream fsCrypt   = new FileStream(cryptFile, FileMode.Create);

            RijndaelManaged RMCrypto = new RijndaelManaged();

            CryptoStream cs = new CryptoStream(fsCrypt,
                                               RMCrypto.CreateEncryptor(key, key),
                                               CryptoStreamMode.Write);

            FileStream fsIn = new FileStream(filepath.Text, FileMode.Open);

            int data;

            while ((data = fsIn.ReadByte()) != -1)
            {
                cs.WriteByte((byte)data);
            }
            fsIn.Close();
            cs.Close();
            fsCrypt.Close();
            File.Delete(filepath.Text);
            File.Move(outpath, filepath.Text);
            Bitmap img     = (Bitmap)pictureBox1.BackgroundImage;
            string Steg_pw = "123";

            if (string.IsNullOrEmpty(embtext))
            {
                MessageBox.Show("Empty string can't be hidden", "Warning");
                return;
            }
            if (string.IsNullOrEmpty(Steg_pw))
            {
                MessageBox.Show("Password can't be empty", "Warning");
                return;
            }

            try
            {
                embtext = RijndaelAlgo.Encrypt(embtext, Steg_pw);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            try
            {
                img = SteganographyHelper.MergeText(embtext, img);
                string filename = DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".png";

                string img_location = "F:\\img\\" + filename;
                img.Save(img_location, ImageFormat.Png);
                string code = "http://localhost" + "/" + filename;


                QRCodeEncoder enc    = new QRCodeEncoder();
                Bitmap        bitMap = enc.Encode(code);
                pictureBox2.BackgroundImage = bitMap as Image;
                SaveFileDialog sav = new SaveFileDialog();
                sav.Filter = "Png Image|*.png|Bitmap Image|*.bmp";

                if (sav.ShowDialog() == DialogResult.OK)
                {
                    switch (sav.FilterIndex)
                    {
                    case 0:
                    {
                        bitMap.Save(sav.FileName, ImageFormat.Png);
                    }
                    break;

                    case 1:
                    {
                        bitMap.Save(sav.FileName, ImageFormat.Bmp);
                    }
                    break;
                    }
                }

                MessageBox.Show("File Encrypted successfully", "Information");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Encryption failed! " + ex.Message, "Error");
            }
        }