private void ExtractAllButton_Click(object sender, EventArgs e) { string decoded; string folder = UrlTextBox.Text; Bitmap temp; // directory does not exist if (Directory.Exists(folder) == false) { return; } DecryptAllTextBox.Text = string.Empty; // get the files in the folder var files = Directory.GetFiles(folder); foreach (var f in files) { // if it is an image file if (ImageExtensions.Contains(Path.GetExtension(f).ToUpperInvariant())) { // get the image file and extract the data temp = ImageToBMP(f); decoded = Steg.Extract(temp); // hidden text was found, so display if (decoded != string.Empty) { DecryptAllTextBox.Text += f.Substring(f.LastIndexOf("\\") + 1) + Environment.NewLine + decoded + Environment.NewLine + Environment.NewLine; } } } }
// user encodes the data private void EncodeButton_Click(object sender, EventArgs e) { text = WordsTextBox.Text; // if the user wants to encrypt the text if (PasswordCheckBox.Checked == true) { text = StringCipher.Encrypt(WordsTextBox.Text, PasswordTextBox.Text); } // exit if there is no bmp file or it is too small if (ValidDetails() == false) { return; } bmp = Steg.Embed(text, bmp); SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save Image"; sfd.DefaultExt = "png"; sfd.Filter = "Png files (*.png)|*.png"; sfd.FilterIndex = 2; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { bmp.Save(sfd.FileName, ImageFormat.Png); } }
private void hideButton_Click(object sender, EventArgs e) { Bitmap bmp = (Bitmap)imagePictureBox.Image; if (message.Text.Equals("") == true) { MessageBox.Show("The text you want to hide can't be empty", "Warning"); } bmp = new Steg().hideText(message.Text, bmp); }
// user decodes data private void DecodeButton_Click(object sender, EventArgs e) { // exit if there is no bmp file if (ValidDetails() == false) { return; } string decoded = Steg.Extract(bmp); // decrypt for the user if (PasswordCheckBox.Checked == true) { try { decoded = StringCipher.Decrypt(decoded, PasswordTextBox.Text); } catch (System.Security.Cryptography.CryptographicException) { MessageBox.Show( "Image or password is incorrect.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } catch (System.FormatException) { MessageBox.Show( "Image was not large enough to hide all text, and therefore the text cannot be extracted.", "Image Size Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } decoded = "Decoded text:" + Environment.NewLine + decoded; WordsTextBox.Text = decoded; }