Sunday, May 2, 2010

Steganography in Java

Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity. (Source: Wikipedia)

The image into which the message is to be hidden is known as the Carrier Image and the message or the file to be hiden is known as the payload.Each bit of the payload is hidden in the Least Significant Bit of either Red, Green and Blue for each pixel.That means we can hide 3 bits of payload per pixel.

Example:

In this example we will hide the letter 'A' (in binary 01000001)

Assume the three carrier pixels in RGB

R: 0011100 0
G: 0110100 1
B: 0000111 1

R: 0011010 0
G: 1000100 1
B: 0010001 0

R: 0011110 0
G: 1000010 0
B: 0011111 0

Here, we change the least significant bits (01101000) to our payload (01000001).
After this, our carrier pixels will be changed to

R: 0011100 0
G: 0110100 1
B: 0000111 0

R: 0011010 0
G: 1000100 0
B: 0010001 0

R: 0011110 0
G: 1000010 1
B: 0011111 0

The difference between 00001111 and  00001110 in the value for blue intensity is likely to be undetectable by the human eye.


Class Description:

Hides a payload(any file), along with an optional message inside the carrier image. Also gives you the
options to compress or to encrypt or to encrypt & compress the file before hiding it in the carrier
image.

Usage:

char[] password = new char[] {'p','a','s','s','w','o','r','d'};// your password, possibly from JPasswordField
Steganograph steg = new Steganograph();
steg.setCompression(true); // enable compression
steg.setEncryption(true); // enable encryption
// hide the file
steg.hide(new File("C:\\path\\to\\carrier\\Pictures"), new File("C:\\path\\to\\secret\\File"), new File("C:\\path\\to\\output\\folder"),"secret message to be encoded", password);
// extract the file
steg.reveal(new File("C:\\path\\to\\steg\\Pictures"),new File("C:\\path\\to\\output\\folder"), password);
Example Image

This is the carrier image, with no hidden stuff in it.



This is the stegnographed image with the source code of this class hidden in it, zipped and encrypted (password is 'password').

The complete source code can be downloaded here.

18 comments:

  1. its saying
    "
    java.security.InvalidKeyException: Illegal key size or default parameters
    "

    ReplyDelete
  2. On a default JVM installation , AES is limited to 128-bit key size. This is a remnant of import/export laws on cryptographic software. To unlock the larger AES key sizes, you need to download and apply the "JCE Unlimited Strength Jurisdiction Policy Files". (see at the bottom of this page [http://www.oracle.com/technetwork/java/javase/downloads/index.html].

    ReplyDelete
  3. can i use your class in my program ?
    i need it for my fyp

    ReplyDelete
    Replies
    1. Yeah sure u can use it. If u can, a link back to this article would be nice, though its not mandatory ;)

      Delete
  4. the source code u have given, is applicable to all file type jpg , giff to png ,bmp.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Replies
    1. can u pls be more specific. Its a netbeans project. you can run it easily with netbeans.

      Delete
  7. Hi, great post.

    One question, why is necessary use carrier and secretFile, with only use secretFile and add to this image the message is enough, ¿is it?

    ReplyDelete
  8. This is a very nice post. But when ever I run it, it's asking me of main method. Pls help me out

    ReplyDelete
    Replies
    1. Hi
      This is a library project. Create a new project with main method, add a reference to this library and use it, as shown in the sample.

      Happy Coding:)

      Delete
  9. This is a very nice post. But when ever I run it, it's asking me of main method. Pls help me out

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Thanks for this post, it is very nice for the beginers like us. But i have a little problem with your implementation. I don't understand why the final image seem to be heavy than the original one.

    ReplyDelete
  12. hi, thanks for making this post. i seem to be stuck at the extracting part. it just wont extract. it keeps refering to this part:

    steg.reveal(new File("C:\\path\\to\\steg\\Pictures"),new File("C:\\path\\to\\output\\folder"), password);

    especially the password part, and

    public void reveal{}

    please help me.

    ReplyDelete