tags:

views:

437

answers:

6
+4  Q: 

Obfuscating images

I want to distribute a few images and not allow others to see them unless they are using my program. My intention will be to use JPG files in which I will alter the header so other image viewers cannot read them anymore. For example I can delete the bytes 7-10 which are the magic signature for JPG. Later, my program will reconstruct the header and show the JPG file.

Question: how do I do this on the fly, without reading the “broken” JPG file, restoring the header, saving the good file to disk and then re-loading it as a “good” JPG file?

+14  A: 

Load the "broken" file into a TMemoryStream, patch the bytes in-memory, and use TGraphic.LoadFromStream() to load the fixed JPG file.

mghie
Darn, you're fast. :-)
Ken White
> Darn, you're fast. :-) – Ken WhiteAgree. Thanks!Me happy :)
Altar
+2  A: 

Mghie's answer is about as good as you'll find, but it's not likely to be too effective. If someone wants to look at your images and they know anything about image formats, they'll open it in a hex editor and most likely recognize what they see as a JPEG with the magic header removed.

If you really want to keep someone from viewing your images, construct your own image format, (it's not as hard as it sounds, really,) and put as little metadata in as possible, and then hope that works. Or encrypt them, or put them into an archive, (construct your own archive format for best results,) and hope that works.

Thing is, ultimately, anything that's encoded has to be decoded before it can be shown, and any sufficiently-talented hacker can trace their way through your decoding routine and figure out how it works. Why are you trying to hide things from your users anyway?

Mason Wheeler
+1  A: 

You could make it more difficult for them by byte packing the images as encrypted resources. But like anything else if they have access to the files that could get the images out. It just depends on how much effort the are willing to use.

Matthew Whited
> It just depends on how much effort the are willing to use.Not too much. I accept that someone may decrypt images. Maybe later I will add additional encryption. But is useless anyway as anybody can PrintScreen the image.
Altar
+5  A: 

Encrypt them. Load the encrypted image, decrypt in memory and then do the loadfromstream like mghie suggested.

Loren Pechtel
+4  A: 

Why not just encrypt the images with a private key and distribute your public key to the people you want to view the images? much easier to distribute a public key than writing some custom software and distributing that. Don't forget; anything displayed on screen can be screen captured. The fact a custom-mangled JPEG can only be displayed with your app is no protection. Also don't forget; people can simply distribute your software with the mangled image.

Blank Xavier
The screen capture point is a good one. You could place something throughout the displayed image using steganography. Then, if the compromised image becomes available to you, you may be able to figure out whose copy was the source. Whether this is useful depends on your domain/needs.
Argalatyr
A: 

Depending on how secure you need it to be you could do something as simple as obfuscate the file extension to an extension that is only opened with your application. This will only work if its not super secret images that you are changing.

Toby Allen