How to Encrypt a File and apply Image Steganography


Steganography is the art and science of writing hidden messages in such a way that no one apart from the intended recipient knows of the existence of the message. Generally, a steganographic message will appear to be something else: a picture, an article, a shopping list, or some other message. A Steganographic message (plaintext) is often first encrypted by some traditional means, and then a covertext is modified in some way to contain the encrypted message (ciphertext) , resulting in stegotext.

In this article, we will teach you how to do this. First to encrypt a message and then apply image steganography techniques to hide this encrypted message in an image.

PHASE # 1: How to encrypt a text/message

When Concealing data within encrypted data, the data to be concealed is first encrypted before being used to overwrite part of a much larger block of encrypted data. This technique works most effectively when the decrypted version of data being overwritten has no special meaning or use. Some cryptosystems, especially those designed for filesystems, add random looking padding bytes at the end of a ciphertext so that its size can’t be used to know what was the plaintext size. We will be applying this encryption technique using TrueCrypt.

TrueCrypt is a free open source disk encryption software that works on both Windows and Linux platforms. No data stored on an encrypted volume can be read (decrypted) without using the correct password/keyfile(s) or correct encryption keys. TrueCrypt does this by creating a virtual hard drive that will read and write encrypted files on the fly. The advantage of using TrueCrypt is that you need not download it everywhere. All you need are the files truecrypt.exe, truecrypt.sys and the volume file you create which you can carry on your flash drive.

Step by Step Tutorial on how to encrypt your Hard disk or data or message using TrueCrypt

Step # 1: Download and install TrueCrypt

Step # 2: Once you Launch TrueCrypt, Click on “Create Volume” button. This launches the Volume Creation wizard that prepares the encryped drive location. Next, choose ” Create a Standard TrueCrypt Volume” and hit Next. Next, click on “Select File” button. Browse to a place where you want to store your encryped files. In this case, I am selecting askstudent.secret Note: This is not the file you want to encrypt. Think of this as a Folder Name which in turn would contain the files you want to encrypt later on. Hit Next

Store Encryped Files

Step # 3: Next, you need to choose your Encryption Algorithm. The default AES is the accepted industry standard and pretty much sets the current bar on encryption. Select AES. Hit Next. If you want more information about the Encryption options, TrueCrypt has some information on Encryption Algorithms and Hash Algorithms.

Choosing File Encryption of AES

Step # 4: Now, choose the size of the virtual drive. If you have an external hard drive or a flash drive which you want encrypted, then choose “Select Device” in the step above and put in the limit you want to set.

In this example, I want to create a single file which is confidential to me. So I choose a smaller size of 100KB.

Hard Disk Size

Step # 5: Now choose your Volume Password. This is the most important step. TrueCrypt wants you to punch in like 20 something characters for a strong password. Although there is no minimum limit, the max limit is 64 characters. For 20 something characters, choose a passphrase instead of coming up with a strong password and then copying and pasting the password somewhere else in plain text.

Selecting a Strong password

Step # 6: Format the volume now. TrueCrypt gathers random information from your system including the location of your mouse pointer and uses this information to format the location you selected earlier. Note: When you hit the “format” button, you are not formatting or erasing your hard drive. You are ONLY formatting the drive location file which in this case would be the askstudent.secrets file I created earlier. Congratulations, you now have an encrypted volume location.

Step # 7: Now that you have an encrypted volume, how do you access or store files in that drive. In TrueCrypt, choose “Select File” and browse to the file, in this case askstudent.secrets which you created earlier. TrueCrypt lists a list of drive letters available on your computer. I choose Z: Now, select the “Mount” button after which you have to enter the master password you created earlier.

Mounting a virtual drive or file

Step # 8: Your virtual drive is now created. Go to My Computer and there will be a new one listed as “Local Disk H:”. This is now like any other drive, only encryped. So you can drag and drop or use “save as” and save your files to this drive. Once you are done, in TrueCrypt, select the mounted drive(H:) and then select the “dismount” button. Once you do this, all you are left with is the askstudent.secrets file which you can then burn or zip it or email it or store it in your thumb drive.

Virtual hard disk created

PHASE # 2: Hiding the encrypted file in an Image using Image Steganography

Step # 1: We have the askstudent.secrets encrypted file from steps above. Now, create a RAR file for this file. You can get WinRar from RarLabs. So you now end up with an image file, askstudent.secrets file and askstudent.secrets.rar file.

AskStudent secret rar file

Step # 2: Now, launch command prompt and browse to the directory where you have the above three files stored.

Step # 3: Now, type ‘copy /b askstudent.png + askstudent.secrets.rar ajit.png‘ where askstudent.png is the original picture, askstudent.secrets.rar is the file to be hidden and ajit.png is the file which contains both.

Hiding file within an image using Command Prompt and WinRar

Step # 4: Now, we have ajit.png created. If you launch this file using WinRar, you will see the askstudent.secrets file.

Hidden File in an image

Here is the image file that was created as the end result

Applying Steganography to hide a file in an image

For a list of more steganography tools including hiding files in Mp3s or JPEGs or other tools, visit jjtc for a list of Tools, Vendor authors, operating system and the various steg types

Editors Warning: The above information is for educational purposes only and should not be used for illegal activities.

If you liked this article, click here to buy me a beer!

11 replies to this post
  1. This isn’t TRUE steganography, steganography is encoding a file directly into an image by slightly changing pixel values (other methods available), what you are doing is sort of hiding the file on the disk with that name, but this is still pretty cool :)

  2. but how you can split again the file so that you can retrieve what you encrypted???

    i mean when you copied the file ” askstudent.png + askstudent.secrets.rar” they became one .. i am right?? now the question is that how can i split the askstudent.png and askstudent.secrets.rar into separate file??

  3. […] Learn how to encrypt & hide content in an image like CIA [link][more] […]

  4. hi

    i have submitted an SBIR/STTR grants on a new steganographic method for data encryption.

    i am looking for funding to help commercialize the technology. any ideas or contacts?



Leave a Reply