This project provides a secure system for encrypting and decrypting files using AES-256 in CBC mode. It compresses files with GZIP, embeds the original filename, and restores it during decryption.
- ✅ Supports multiple file extensions (e.g.,
.csv
,.json
,.txt
) - ✅ Automatically compresses and encrypts new files in a watch directory
- ✅ Adds timestamp + random ID to encrypted file names
- ✅ Decryption restores the original filename and extension
- ✅ Uses AES encryption with PKCS7 padding
- ✅ Logs activity and errors for auditing
- ✅ Real-time file monitoring using
watchdog
- ✅ CLI interface to select encryption or decryption mode
- Python 3.7+
cryptography
librarywatchdog
library.env
file with the following config keys:
watch_directory=./input
staging_directory=./staging
output_directory=./output
encryption_key=BASE64_ENCODED_AES_KEY
file_extensions=csv,txt,json
sleep_interval_min=60
sleep_interval_max=120
Use a base64-encoded AES key (16, 24, or 32 bytes after decoding).
Install dependencies with:
pip install -r requirements.txt
Run the main script to choose between encryption or decryption:
python main.py encrypt
or
python main.py decrypt
This uses a command-line interface with subcommands for flexibility.
- Place a sample
.csv
,.json
, or.txt
file in thewatch_directory
. - Run
python main.py encrypt
— it will be encrypted and moved tostaging_directory
. - Run
python main.py decrypt
— it will decrypt it back into theoutput_directory
.
.
├── enc.py
├── dec.py
├── main.py
├──env_loader.py
├──key_rotation.py
├──logging_system.py
├── .env
├── setup.py
├── requirements.txt
├── LICENSE
├── /input
├── /staging
└── /output
- Encryption uses AES-CBC with a securely generated IV.
- Original filenames are embedded in encrypted files for reliable restoration.
- Decrypted files are only saved if decryption and decompression succeed.
- Rotate the AES key periodically using key_rotation.py, KEEP A COPY OF YOUR KEY to be apply to decrypt your old files.
- Use
watchdog
for real-time directory monitoring.
MIT — free to use and modify. See LICENSE
file.
[Mohamadali122]