Esempio n. 1
0
        private void stegEncrypt(object sender, RoutedEventArgs e)
        {
            string fileName;

            byte[] hideThis;
            Bitmap bmp;

            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                fileName = dlg.FileName;
                string fileExtention = fileName.Substring(fileName.Length - 3);
                if (!fileExtention.Equals("bmp"))
                {
                    bmp = Steganography.ConvertToBitmap(fileName);
                }
                else
                {
                    byte[] imageData = System.IO.File.ReadAllBytes(@fileName);
                    using (var ms = new MemoryStream(imageData))
                    {
                        bmp = new Bitmap(ms);
                    }
                }
                OpenFileDialog dlg1 = new OpenFileDialog();
                if (dlg1.ShowDialog() == DialogResult.OK)
                {
                    stegPass = stegPassBox.Text;
                    hideThis = File.ReadAllBytes(dlg1.FileName);

                    byte[] stegByte = Convert.FromBase64String(stegPass);

                    while (stegByte.Length != 32)
                    {
                        stegByte = stegByte.Concat(Encoding.ASCII.GetBytes("0")).ToArray();
                        Console.WriteLine(stegByte);
                    }

                    byte[]        IV           = File.ReadAllBytes(@"C:\\Users\\SengokuMedaru\\Desktop\\keys\\IV.txt");
                    KeyController kc           = new KeyController();
                    byte[]        EncryptedStr = kc.symmetricEncryption(hideThis, stegByte, IV);
                    String        hideThisStr  = System.Text.Encoding.UTF8.GetString(EncryptedStr);
                    bmp      = Steganography.embedText(hideThisStr, bmp);
                    fileName = System.IO.Path.GetFileNameWithoutExtension(fileName);

                    bmp.Save(@"C:\\Users\\SengokuMedaru\\Desktop\\EncryptedText\\Harmless " + fileName + ".bmp");
                    Console.WriteLine("A txt file has successfully been hidden in " + fileName + "!");
                    Console.WriteLine("");
                }
            }
        }
        private Bitmap stegEncrypt(object sender, RoutedEventArgs e)
        {
            string fileName;

            byte[] hideThis;
            Bitmap bmp = null;

            while (bmp == null)
            {
                System.Windows.MessageBox.Show("Select an image carrier");

                OpenFileDialog dlg = new OpenFileDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    fileName = dlg.FileName;
                    string fileExtention = fileName.Substring(fileName.Length - 3);
                    if (!fileExtention.Equals("bmp"))
                    {
                        bmp = Steganography.ConvertToBitmap(fileName);
                    }
                    else
                    {
                        byte[] imageData = System.IO.File.ReadAllBytes(@fileName);
                        using (var ms = new MemoryStream(imageData))
                        {
                            bmp = new Bitmap(ms);
                        }
                    }

                    System.Windows.MessageBox.Show("Select the txt file you wish to embed");


                    OpenFileDialog dlg1 = new OpenFileDialog();
                    if (dlg1.ShowDialog() == DialogResult.OK)
                    {
                        hideThis = File.ReadAllBytes(dlg1.FileName);
                        stegPass = Controllers.Prompt.ShowDialog3("Enter password", "Prompt");
                        if (stegPass.Length < 8)
                        {
                            System.Windows.MessageBox.Show("Please enter an 8-character password");
                        }
                        else
                        {
                            if (stegPass.Length >= 8)
                            {
                                stegPass = stegPass.Substring(0, 8);
                            }
                            byte[] stegByte = Convert.FromBase64String(stegPass);

                            while (stegByte.Length != 32)
                            {
                                stegByte = stegByte.Concat(Encoding.ASCII.GetBytes("0")).ToArray();
                                Console.WriteLine(stegByte);
                            }

                            byte[]        IV           = File.ReadAllBytes(@bigPath + "\\IV.txt");
                            KeyController kc           = new KeyController();
                            byte[]        EncryptedStr = kc.symmetricEncryption(hideThis, stegByte, IV);
                            String        hideThisStr  = Convert.ToBase64String(EncryptedStr);
                            bmp      = Steganography.embedText(hideThisStr, bmp);
                            fileName = System.IO.Path.GetFileNameWithoutExtension(fileName);
                        }
                    }
                }
            }
            return(bmp);
        }