This project implements a hybrid encryption system in Python that combines the strengths of both asymmetric (RSA) and symmetric (AES) encryption to securely encrypt and decrypt files.
- π RSA key pair generation (
2048-bit) - π File encryption using AES-256 in CBC mode
- π AES key encryption using RSA and OAEP padding
- π¦ Simple CLI for encryption, decryption, and key management
- β Padding support for block alignment
-
Key Generation
- Generates a public-private RSA key pair (
private.pemandpublic.pem).
- Generates a public-private RSA key pair (
-
Encryption
- A random AES-256 key and IV are generated.
- File content is encrypted using AES.
- AES key is encrypted using the RSA public key.
- Encrypted output:
[IV][Encrypted AES Key][Encrypted File Data]with.encextension.
-
Decryption
- Extracts IV and AES key from encrypted file.
- Decrypts AES key using RSA private key.
- Decrypts file using the AES key.
hybridencrypt.py # Main Python script private.pem # RSA private key (generated) public.pem # RSA public key (generated) yourfile.txt # Your input file yourfile.txt.enc # Encrypted output yourfile_decrypted.txt # Output after decryption
yaml Copy Edit
β οΈ Recommended: Use a Python virtual environment.
python3 -m venv venv
source venv/bin/activate
pip install pycryptodome
2. Run Script
python hybridencrypt.pyFollow the prompt:
G to generate RSA keys
E to encrypt a file
D to decrypt a .enc file
π¦ Dependencies Install using pip:
pip install pycryptodomeMake sure you're not using pycrypto β it's outdated. Use pycryptodome.
π Security Notes RSA private keys are stored unprotected. Consider securing them with passphrases or using a secure key store.
No file authentication is included β for production use, consider adding HMAC for integrity.
Avoid storing keys and encrypted files in the same directory in real deployments.