A Python-based encryption system that combines RSA and AES encryption algorithms to provide secure message encryption. This hybrid approach leverages the strengths of both symmetric (AES) and asymmetric (RSA) encryption.
The system uses a hybrid encryption approach:
- Message Encryption: Your message is encrypted using AES-256-ECB
- Key Protection: The AES key is encrypted using RSA-2048
- Storage: Both encrypted message and encrypted AES key are saved securely
This approach combines:
- AES: Fast symmetric encryption for large messages
- RSA: Secure asymmetric encryption for key exchange
- Hybrid Encryption: RSA + AES encryption for optimal security and performance
- Key Management: Automatic RSA key pair generation and secure storage
- Multiple Encryption Modes:
- Hybrid encryption (RSA + AES)
- AES-only encryption
- RSA-only encryption
- Secure Decryption: Complete decryption system with error handling
- File Management: Encrypted data saved in JSON format
- User-Friendly Interface: Interactive command-line interface
pip install rsa cryptographyrsa: RSA encryption/decryptioncryptography: AES encryption and cryptographic primitivespickle: Key serializationjson: Data storage format
- Clone or download the project files
- Install required dependencies:
pip install rsa cryptography
- Run the encryption system:
python encrypt.py
Run the encryption script:
python encrypt.pyAvailable Options:
- Generate new keys and encrypt - Creates new RSA key pair and encrypts your message
- Use existing keys to encrypt - Uses previously generated keys for encryption
- AES-only encryption - Encrypts using only AES-256
- RSA-only encryption - Encrypts using only RSA (limited message size)
- Exit - Quit the program
Run the decryption script:
python decrypt.pyAvailable Options:
- Decrypt hybrid encrypted message - Decrypts RSA + AES encrypted data
- Decrypt AES-only encrypted message - Decrypts AES-only data
- Decrypt RSA-only encrypted message - Decrypts RSA-only data
- Decrypt custom hybrid data - Specify custom file paths for decryption
- List available encrypted files - Show all available encrypted files
- Exit - Quit the program
After running the encryption system, the following files will be created:
├── encrypt.py # Main encryption script
├── decrypt.py # Main decryption script
├── keys/ # Directory for RSA keys
│ ├── private_key.pkl # RSA private key (keep secret!)
│ └── public_key.pkl # RSA public key
├── encrypted_data.json # Hybrid encrypted data
├── aes_encrypted.json # AES-only encrypted data (if used)
└── rsa_encrypted.json # RSA-only encrypted data (if used)
- Key Size: 2048-bit RSA keys
- Storage: Keys are saved as pickle files in the
keys/directory - Security: Keep your private key (
private_key.pkl) secure and secret
- Key Size: 256-bit AES keys
- Generation: Randomly generated for each encryption
- Protection: AES keys are encrypted with RSA before storage
{
"encrypted_message": "hex_encoded_aes_encrypted_message",
"encrypted_aes_key": "hex_encoded_rsa_encrypted_aes_key",
"encryption_method": "AES-256-ECB + RSA-2048",
"timestamp": "encryption_timestamp"
}- RSA-2048: Industry-standard asymmetric encryption
- AES-256: Advanced symmetric encryption
- PKCS7 Padding: Proper message padding for AES
- Secure Key Generation: Cryptographically secure random key generation
- Key Separation: AES keys are never stored in plaintext
- Keep Private Keys Safe: Never share your private key file
- Backup Keys: Store copies of your keys in a secure location
- Message Size Limits: RSA-only mode has message size limitations
- Key Dependencies: You need the private key to decrypt any encrypted data
-
First Time Setup:
python encrypt.py # Choose option 1 to generate new keys # Enter your message # Keys and encrypted data are saved
-
Decrypt Your Message:
python decrypt.py # Choose option 1 for hybrid decryption # Your original message is recovered
-
Subsequent Encryptions:
python encrypt.py # Choose option 2 to use existing keys # Enter new message to encrypt
- This implementation uses ECB mode for AES, which is suitable for demonstration but consider CBC/GCM for production
- Store private keys in secure locations
- Consider implementing additional authentication mechanisms for production use
- Regular key rotation is recommended for high-security applications
Feel free to contribute improvements, bug fixes, or additional features to this hybrid encryption system.
This project is provided as-is for educational and development purposes.