Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding secrets inside photographs with php

I have created a service that hides text inside photographs. For example:

$img_name = "myimage.jpeg";
$orig_contents = file_get_contents($img_name);
$msg = "My secret.";

$fp = fopen($img_name, "wb"); 
fwrite($fp, $orig_contents . $msg); 
fclose($fp); 

I'm curious: How much information can I hide inside photographs using this method? For example, could I embed chapters of a novel in an image file? I have added fairly large blocks of text without corrupting the image, but I'm wondering if PHP or image viewing applications impose limits on this.

(P.S. I am aware that this type of steganography is insecure; I'm just doing this for fun.)

like image 896
hawkharris Avatar asked Oct 10 '13 21:10

hawkharris


People also ask

How do I hide content in a picture?

Easy Way – Use ImageHide When you launch it, click Load Image and choose the picture you want to hide text in. It can be any image format, but keep in mind that the resulting file will be in PNG or BMP format. After the image is loaded, type or paste whatever text you want to hide in the bottom field.

What is the technique used to hide information inside a picture?

Steganography can be used to conceal almost any type of digital content, including text, image, video or audio content; the data to be hidden can be hidden inside almost any other type of digital content.

Is steganography only about hiding words inside of pictures?

Steganography is the practice of hiding a secret message inside of (or even on top of) something that is not secret. That something can be just about anything you want to embed a secret piece of text inside of a picture. Or hiding a secret message or script inside of a Word or Excel document.

Is the art of hiding information inside image files?

Steganography includes the concealment of information within computer files. In digital steganography, electronic communications may include steganographic coding inside of a transport layer, such as a document file, image file, program, or protocol.


3 Answers

You should take a look at Steganography. And be aware you are not hidding your data in the image. Anyone who could open the image with a text editor would see your text somewhere in the file (in this case, in the end, which is much worse). If I were you, I'd do the following:

  1. Encrypt your data with some decent Algorithm and a strong key
  2. Create a function that distributes your data through the file in a pseudo-random way, so that anyone would note that you're trying to put something secret in it (be aware you have to recover it afterwards). In a regular bitmap image, you can use the last bit of each pixel to save your information, since this change made by it would not be perceived by human eye, if you compared the original image with the one that has hidden data.
  3. Pray NSA isn't reading this, otherwise you can get some serious trouble :)
like image 115
fvdalcin Avatar answered Oct 18 '22 00:10

fvdalcin


No, there's essentially no limit imposed by either PHP or the JPEG format on how much data you'll be able to add to an image using this method. This works because the JPEG format stores all of the image data at the beginning of the file until some marker. After the marker, any data is assumed to be something else like a thumbnail, for example.

One cool trick (that also works with GIF images) is that you can append a ZIP file to the end of an image and the file works as both a JPEG and a ZIP file. It will be readable by both image processing programs or ZIP programs just by changing the file extension.

like image 25
Bill the Lizard Avatar answered Oct 18 '22 01:10

Bill the Lizard


I think this is not the most secure way to do it, if you really want to hide string into an image, you will probably use a specific pattern to change a pixel every 10 pixels, the idea is simple convert your image to an array of integer, loop through the array and every 10 pixels change the value to the ascii character number.

Changing 1 each 10 pixel won't make a lot of noise.

To make it more secure use encoding, so use your own map to encode ascii, like @fvdalcin proposed.

like image 1
Mehdi Karamosly Avatar answered Oct 18 '22 02:10

Mehdi Karamosly