Skip to content
Duong Nguyen edited this page Jul 23, 2019 · 2 revisions

Index

As a package

Create a encryptor object to encrypt your plain text data

Option 1: encrypt data using AES:

from steganosaurus.fernet_cryptor import FernetCryptor

password = "letmein"
key_stretch = 1000 # Use key stretching 1000 times when generating encryption key from password
encryptor = FernetCryptor(key_stretch)

Option 2: encrypt data using One-time-Pad (OTP). If used properly, OTP is mathematically secure. However, the following conditions must be satisfied:

  • The pad must be as long as secret data.
  • The pad must be truly random (cryptographically random is not good enough).
  • The pad must never be reused. .
from steganosaurus.otp_cryptor import OTPCryptor

encryptor = OTPCryptor()
otp_file_path = 'C:/my_otp_file.bin' # a binary file to be used as one-time-pad
with open(args.password, 'rb') as f:
    password = f.read()

Create a modifier object to hide / retrieve data from the image file

from steganosaurus.picture_modifier import PictureModifier

level = 2 # the number of low-bit in each pixel we use to store secret data
modifier = PictureModifier(level)

level can take any value between 1 and 8. However, the higher level is, the more different the image with steganography will be. For the best result, a level of 1 or 2 is recommended.

Hide secret data into image

Load image file's data and secret file data

with open('C:/path_to_image_file.png', 'rb') as f:
    medium_data = f.read()
with open('C:/path_to_secret_file.txt', 'rb') as f:
    secret_data = f.read()

Modify image file and export new image file to disk

from steganography import Steganography

steganography = Steganography(modifier, encryptor)
format = 'PNG'
file_with_secret = steganography.hide_file(password, medium_data, secret_data, format)
with open('C:/path_to_image_file_with_secret.png', 'wb') as f:
    f.write(file_with_secret) 

Retrieve secret data from image

Load image file with hidden secret

with open('C:/path_to_image_file_with_secret.png', 'rb') as f:
    medium_data = f.read()

Retrieve secret data and write to new location

from steganography import Steganography

steganography = Steganography(modifier, encryptor)
secret_data = steganography.get_file(password, medium_data)
with open('C:/path_to_retrieved_secret_file.txt', 'wb') as f:
    f.write(secret_data)

Note

  • Image must be in PNG or BMP format (lossless).

Run script directly from command-line

You can run steganography.py script from command line, make sure to install the package via pip first.

To hide file into image, with AES encryption

python steganography.py --mode=encrypt --encryption=aes --key_stretch=10000 --level=2 --medium=C:\image.png --password=letmein --secret=C:\secret_file.txt --result=C:\image_with_secret_data.png --format=PNG

To retrieve file from image, with AES encryption

python steganography.py --mode=decrypt --encryption=aes --key_stretch=10000 --level=2 --medium=C:\image.png --password=letmein --result=C:\secret_file.txt

To hide file into image, with OTP encryption

python steganography.py --mode=encrypt --encryption=otp --level=2 --medium=C:\image.png --password=C:\otp_pad.bin --secret=C:\secret_file.txt --result=C:\image_with_secret_data.png --format=PNG

To retrieve file from image, with OTP encryption

python steganography.py --mode=decrypt --encryption=otp --level=2 --medium=C:\image_with_secret_data.png --password=C:\otp_pad.bin --result=C:\secret_file.txt

Note

  • Image must be in PNG or BMP format (lossless).
  • Use encrypt mode to hide secret file into image, use decrypt mode to retrieve secret file from image.
  • Right now only 2 encryption modes are supported, aes for AES encryption and otp for OTP encryption.
  • level used when retrieving secret file must match level used when hiding file.