A Python-based steganography tool that hides files within images using RSA encryption for secure data embedding. This repository provides bidirectional functionality for encoding files into images and decoding them back.
CRIS allows you to:
- Encode a file into an image (PNG) by scattering its bytes across the image's pixels.
- Decode an encrypted file from an image using a private RSA key.
The encoding process includes:
- Storing the file length in the image header (pixel (0,0)).
- Encrypting a seed for shuffling the data placement within the image.
- Distributing the file bytes across the image using a shuffled order.
The decoding process retrieves the file by reversing these steps.
- RSA Encryption: The tool uses RSA encryption to secure the seed used for shuffling the data placement within the image.
- Shuffling: The seed determines the order in which the file bytes are embedded into the image's pixels.
- File Length Header: The first pixel (0,0) stores the file length as a 4-byte header.
- Encrypted Seed: The seed is encrypted using the public key and stored in a fixed set of pixels (row 0, starting from y=1).
- Convert the image to RGBA format.
- Read the file to be encoded.
- Generate a seed, encrypt it using RSA, and store it in the image.
- Shuffle the available pixels using the seed.
- Embed the file bytes into the shuffled pixel locations.
- Read the file length from the header pixel (0,0).
- Decrypt the seed using the private key.
- Reconstruct the shuffled pixel order using the decrypted seed.
- Extract the file bytes from the image.
Download the latest version ...and thats all.
- Python 3.x
Pillowlibrary (for image handling)rsalibrary (for RSA encryption)
To install the required libraries:
pip install Pillow rsapython keygen.pypython encoder.py --file <your_file_path> --image <your_image_path> --key <public_key_path>python decoder.py --image <encoded_image_path> --output <output_file_path> --key <private_key_path>python keygen.py
Enter key name: example
RSA keys saved as 'example_public.pem' and 'example_private.pem'-
Create a text file.
echo "Hello, CRIS!" > secret.txt
-
Encode the text file into an image.
python encode.py --file secret.txt --image input.png --key example_public.pem
Example Output:
Encoded 13 bytes into encoded_input.png Seed Size: 64 bytes -
The resulting image
encoded_input.pngnow contains your file!
-
Decode the image to retrieve the hidden file.
python decode.py --image encoded_input.png --output output.txt --key example_private.pem
Example Output:
File length: 13 bytes Seed decrypted successfully Decoded file saved to output.txt -
Verify the decoded file.
cat output.txt
Output:
Hello, CRIS!
Contributions are welcome! If you find any issues or want to suggest improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- RSA Encryption: https://en.wikipedia.org/wiki/RSA_(cryptosystem)
- Steganography: https://en.wikipedia.org/wiki/Steganography
This implementation is for demonstration purposes as the data is still in the encoded image, just scattered, and the more data gets encoded into an image, the more obvious it is. And may not be suitable for production use. Using steganography and RSA encryption may not provide complete anonymity or security against advanced attacks.
- Juan Pablo Garrido (contact@jpgp.es)
