views:

413

answers:

2

I'm trying to open a file to bytes, convert it to a string, modify some data (think Steganography) and convert the file back to bytes and save it as a jpeg. So far, everything I've tried has corrupted the file in converting it to a string. I've tried converting it to a 64-bit string, but of course that's a bit hard to modify the data in :P

Any suggestions on how I can do this properly, without corrupting my file?

+1  A: 

I don't have this in C# but in PHP, but you can take a look and adaptate to C#.

http://www.havenard.110mb.com/fotomagica/

This is my site where there's a tool to modify the EXIF data of a JPEG and build "magic pictures" which display something in the thumbnail which is not the real picture.

It opens the JPEG, slice its sectors, and build it back ignoring irrelevant sectors and placing my custom made EXIF header.

And this is the source of the PHP classes: http://www.havenard.110mb.com/fotomagica/class.JpegMapper.php.txt (ExifMapper is incomplete) http://www.havenard.110mb.com/fotomagica/class.DataMapper.php.txt

You can study it and rebuild in C#, it is really simple to slice a JPEG as you will see.

Usage of this PHP class (only JpegMapper):


$jpg = new JpegMapper('picture.jpg');
$jpg->save_filtered('filtere picture.jpg'); // save removing irrelevant sectors

It is great to get any JPEG even smaller (sometimes a lot smaller).

Havenard
A: 

Any luck with this?

Chris
Not really. We more or less had to end up using a database. It worked out better in the end. AFAIK .NET 3.0 can modify this data without any trouble.
Reactor5