A robust hybrid image encryption framework combining symmetric and asymmetric cryptography to secure image data.
- 📌 Overview
- ❗️ Prerequisites
- ⚙️ Getting Started
- 📁 Project Directory Structure
- 📝 License
- 🙋♂️ Maintainer
This project implements a hybrid image encryption framework that sequentially applies two layers of encryption—asymmetric (ECC) followed by symmetric (ChaCha20)—to provide enhanced security for digital images.
Unlike traditional hybrid encryption schemes where the symmetric key is encrypted by an asymmetric algorithm, this approach directly encrypts the image itself with both ECC and ChaCha20 in a cascaded fashion. This adds redundancy, complexity, and resilience against cryptographic attacks.
- An input image is first encrypted using Elliptic Curve Cryptography (ECC)—a modern public-key encryption algorithm known for its strength and compact key sizes.
- The ECC-encrypted image is then passed through the ChaCha20 stream cipher for a second layer of symmetric encryption.
- The resulting doubly encrypted image is stored, ensuring that compromising a single encryption layer does not expose the original image.
- During decryption, the image undergoes ChaCha20 decryption first, followed by ECC decryption, to recover the original image.
This dual-layer strategy makes the system suitable for use cases requiring strong confidentiality guarantees—such as secure image storage, transmission over untrusted networks, or cryptographic research.
- Git
- Python 3.12+
- uv - Python package and project manager
git clone https://github.com/roydevashish/hybrid‑technique‑for‑image‑encryption.git
cd hybrid‑technique‑for‑image‑encryption
uv sync
Create a .env
file in the root directory with the following:
IMG_ORIGINAL=dataset
IMG_ENCRYPTED=output/encrypted
IMG_DECRYPTED=output/decrypted
IMG_ORIGINAL_FOR_NPCR=output/original_for_npcr
IMG_ENCRYPTED_FOR_NPCR=output/encrypted_for_npcr
CROPED_ENCRYPTED_IMG=output/croped_for_mse_psnr
ANALYSIS_DIR=output/analysis
CHACHA20_KEY=YOUR_CHACHA20_KEY_64_HEX_CHARACTER
CHACHA20_NONCE=YOUR_CHACHA20_NONCE_16_HEX_CHARACTER
ECC_PRIVATE_KEY=YOUR_ECC_PRIVATE_KEY_16_HEX_CHARACTER
Copy the original images that to be encrypted to the /dataset
folder.
uv run main.py
It will encrypt all the images at the /dataset
folder and save the encrypted images at /output/encrypted
folder, and decrypt all the encrypted images and save it to /output/decrypted
folder.
root
|-- dataset (Original images to be encrypted)
| |-- sample.png
|
|-- output
| |-- analysis (Analysis results/reports)
| | |-- entropy.csv (Entropy Analysis)
| |
| |-- decrypted (Decrypted images)
| | |-- sample.png
| |
| |-- encrypted (Encrypted images)
| |-- sample.png
|
|-- src
| |-- analysys (Analysis logic)
| | |-- __init__.py
| | |-- entropy.py
| | |-- main.py
| |
| |-- app (Core logic)
| |-- __init__.py
| |-- chacha20.py
| |-- ecc.py
| |-- equation.py
| |-- hybrid.py
| |-- image.py
| |-- main.py
| |-- matrix.py
| |-- padding.py
|
|-- .env.sample (Sample file for .env)
|-- .gitignore
|-- .python-version
|-- main.py (entry point)
|-- pyproject.toml
|-- README.md
|-- uv.lock
main.py
— 🚀 Entry point of the project. Runs the hybrid encryption and decryption pipeline.README.md
— 📄 Documentation for setting up and understanding the project..env.sample
— ⚙️ Sample environment file defining secrets and path variables..gitignore
— 🚫 Specifies files and folders to ignore in version control..python-version
— 🐍 Python version specifier (used by tools likepyenv
).pyproject.toml
— 📦 Project metadata and dependency definitions.uv.lock
— 🔒 Lockfile containing pinned dependency versions for reproducibility.
- Contains original input images to be encrypted.
- Example:
sample.png
— raw/original image used for encryption.
- Stores all result related to project.
output/analysis/
— 📊 Contains analysis results/reports.output/encrypted/
— 💾 Contains images after encryption.output/decrypted/
— 🔓 Contains images that were decrypted (should match originals).
File | Description |
---|---|
__init__.py |
Initializes the Python module. |
chacha20.py |
Symmetric encryption via ChaCha20 stream cipher. |
ecc.py |
Asymmetric encryption via ECC (Elliptic Curve Cryptography). |
equation.py |
Solves quadratic equations used in calculation of dimensions of encrypted image. |
hybrid.py |
Core pipeline combining ECC + ChaCha20 (hybrid encryption/decryption). |
image.py |
Converts image to matrix and matrix back to image. |
main.py |
Coordinates encryption/decryption of all images at /dataset folder. |
matrix.py |
Converts matrix to string and string back to matrix. |
padding.py |
Applies/removes padding to/from string with image metadata (height and width). |
File | Description |
---|---|
__init__.py |
Initializes the Python module. |
entropy.py |
Calculate entropy of input, encrypted and decrypted images and write it to output/analysis/entropy.csv file. |
main.py |
Coordinates all analysis. |
No license specified as of now.
GitHub: @roydevashish