/// <summary> /// Embed content /// </summary> /// <param name="sender">caused the event</param> /// <param name="e">event params</param> private void embedButton_Click(object sender, EventArgs e) { // var init Boolean success = false; // show an error if nothing to embed if (this.destFile.Text.Trim() == String.Empty) { MessageBox.Show("You must supply a destination file in which to embed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if ((ContentType)Enum.Parse(typeof(ContentType), this.embedContentType.SelectedItem.ToString()) == ContentType.Text) { if (this.embedText.Text.Trim() == String.Empty) { MessageBox.Show("You must supply text to embed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { EmbeddingContent content = new EmbeddingContent(this.embedText.Text); EmbeddingPlane planes = (EmbeddingPlane)Enum.Parse(typeof(EmbeddingPlane), this.embedPlane.SelectedItem.ToString()); byte bitDepth = Convert.ToByte(this.embedBitDepth.SelectedItem.ToString()); using (Bitmap img = SteganographyMethods.Embed(this.sourceFile.Text.Trim(), planes, bitDepth, content)) { ImageFormat format = (this.destFileType.SelectedItem.ToString() == "Bmp") ? ImageFormat.Bmp : ImageFormat.Png; success = MainWindow.SaveImgToFile(img, this.destFile.Text.Trim(), format); } } } else if ((ContentType)Enum.Parse(typeof(ContentType), this.embedContentType.SelectedItem.ToString()) == ContentType.File) { if (this.embedFile.Text.Trim() == String.Empty) { MessageBox.Show("You must supply a file to embed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { EmbeddingContent content = new EmbeddingContent(new FileInfo(this.embedFile.Text.Trim())); EmbeddingPlane planes = (EmbeddingPlane)Enum.Parse(typeof(EmbeddingPlane), this.embedPlane.SelectedItem.ToString()); byte bitDepth = Convert.ToByte(this.embedBitDepth.SelectedItem.ToString()); using (Bitmap img = SteganographyMethods.Embed(this.sourceFile.Text.Trim(), planes, bitDepth, content)) { ImageFormat format = (this.destFileType.SelectedItem.ToString() == "Bmp") ? ImageFormat.Bmp : ImageFormat.Png; success = MainWindow.SaveImgToFile(img, this.destFile.Text.Trim(), format); } } } // notify if the operation is successful if (success == true) { MessageBox.Show("The operation was completed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void TestBMPTextEmbedDepth2RGBtoBMPandPNG() { // build content const String TEST_MESSAGE = "this is a test message to check to make sure it works!"; EmbeddingContent ec = new EmbeddingContent(TEST_MESSAGE); EmbeddingContent recovered = null; // embed using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.RGB, 2, ec)) { Assert.IsNotNull(img); using (Bitmap png = new Bitmap(img)) { png.Save("testout.bmp", System.Drawing.Imaging.ImageFormat.Bmp); png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png); } } // extract bmp recovered = SteganographyMethods.Extract("testout.bmp", EmbeddingPlane.RGB, 2); // test Assert.IsNotNull(recovered); String recoveredMessage = Encoding.ASCII.GetString(recovered.Content); Assert.AreEqual(recoveredMessage, TEST_MESSAGE); Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text); // extract png recovered = null; recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.RGB, 2); // test Assert.IsNotNull(recovered); recoveredMessage = Encoding.ASCII.GetString(recovered.Content); Assert.AreEqual(recoveredMessage, TEST_MESSAGE); Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text); // cleanup File.Delete("testout.bmp"); File.Delete("testout.png"); }
public void TestPNGRandGandBDepth1() { // build content const String TEST_MESSAGE = "this is a test message to check to make sure it works!"; EmbeddingContent ec = new EmbeddingContent(TEST_MESSAGE); EmbeddingContent recovered = null; // embed R using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.R, 1, ec)) { Assert.IsNotNull(img); using (Bitmap png = new Bitmap(img)) { png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png); } } // extract R recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.R, 1); Assert.IsNotNull(recovered); // test R String recoveredMessage = Encoding.ASCII.GetString(recovered.Content); Assert.AreEqual(recoveredMessage, TEST_MESSAGE); Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text); // cleanup R recovered = null; File.Delete("testout.png"); // embed G using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.G, 1, ec)) { Assert.IsNotNull(img); using (Bitmap png = new Bitmap(img)) { png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png); } } // extract G recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.G, 1); Assert.IsNotNull(recovered); // test G recoveredMessage = Encoding.ASCII.GetString(recovered.Content); Assert.AreEqual(recoveredMessage, TEST_MESSAGE); Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text); // cleanup G recovered = null; File.Delete("testout.png"); // embed B using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.B, 1, ec)) { Assert.IsNotNull(img); using (Bitmap png = new Bitmap(img)) { png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png); } } // extract B recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.B, 1); Assert.IsNotNull(recovered); // test B recoveredMessage = Encoding.ASCII.GetString(recovered.Content); Assert.AreEqual(recoveredMessage, TEST_MESSAGE); Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.Text); // test wrong extraction from G is null (should be B) using (Bitmap img = new Bitmap("testout.png")) { recovered = SteganographyMethods.Extract(img, EmbeddingPlane.G, 2); } Assert.IsNull(recovered); // cleanup B File.Delete("testout.png"); }
public void TestBMPFileEmbedDepth2RGBtoBMPandPNG() { // var init EmbeddingContent ec = new EmbeddingContent(new FileInfo("embedfile.jpg")); EmbeddingContent recovered = null; int height; int width; // get info aboud the embed file using (Bitmap embedfile = new Bitmap("embedfile.jpg")) { height = embedfile.Height; width = embedfile.Width; } // embed using (Bitmap img = SteganographyMethods.Embed("test.bmp", EmbeddingPlane.RGB, 2, ec)) { Assert.IsNotNull(img); using (Bitmap png = new Bitmap(img)) { png.Save("testout.bmp", System.Drawing.Imaging.ImageFormat.Bmp); png.Save("testout.png", System.Drawing.Imaging.ImageFormat.Png); } } // extract file from BMP, get info recovered = SteganographyMethods.Extract("testout.bmp", EmbeddingPlane.RGB, 2); Assert.IsNotNull(recovered); File.WriteAllBytes("recovered.jpg", recovered.Content); // test Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.File); Assert.AreEqual(recovered.Content.Length, (new FileInfo("recovered.jpg")).Length); using (Bitmap embedfile = new Bitmap("recovered.jpg")) { Assert.AreEqual(height, embedfile.Height); Assert.AreEqual(width, embedfile.Width); } // cleanup recovered = null; File.Delete("recovered.jpg"); // extract from PNG recovered = SteganographyMethods.Extract("testout.png", EmbeddingPlane.RGB, 2); Assert.IsNotNull(recovered); File.WriteAllBytes("recovered.jpg", recovered.Content); // test Assert.AreEqual(recovered.Header.TypeOfContent, ContentType.File); Assert.AreEqual(recovered.Content.Length, (new FileInfo("recovered.jpg")).Length); using (Bitmap embedfile = new Bitmap("recovered.jpg")) { Assert.AreEqual(height, embedfile.Height); Assert.AreEqual(width, embedfile.Width); } // cleanup File.Delete("recovered.jpg"); File.Delete("testout.bmp"); File.Delete("testout.png"); }