A secure encryption tool combining RSA and AES algorithms for protecting sensitive data and files. This program provides robust encryption, decryption, key management, and file obfuscation features for improved security.
- Introduction
- Features
- Requirements
- Installation
- Usage Guide
- How It Works
- Security Measures
- Contributing
- License
This program handles secure encryption and decryption of data using AES (for symmetric encryption) and RSA (for asymmetric encryption). Key management is simplified with obfuscated key files that include RSA key pairs and AES keys, optionally secured with a password.
- AES Encryption: Encrypts and decrypts data or files using a 256-bit symmetric key.
- RSA Key Management: Uses a 4096-bit RSA key pair to secure AES keys.
- Obfuscation: Adds Base64 encoding and reversible string manipulation for additional protection of key files.
- File Encryption: Supports encrypting and decrypting files directly with
.encextensions. - Key File Hashing: Enhances AES key security by integrating a hash of the key file for integrity verification.
- Python 3.x
- cryptography library: Install via
pip install cryptography.
- Clone or download the script to your project directory.
- Install required Python dependencies:
pip install cryptography
Generate a key file if one does not exist.
- Specify a path for the key file (e.g.,
keyfile.key). - Optionally provide a password to secure the key file.
initialize_key_file("keyfile.key", "your-secure-password")Encrypt strings or binary data with the following function:
encrypt_data("keyfile.key", "your-password", b"Your sensitive data")Output: A Base64-encoded string containing the encrypted data.
Retrieve and decrypt previously encrypted strings or binary data:
decrypt_data("keyfile.key", "your-password", "encrypted_data_string")Output: The original unencrypted data.
Encrypt files directly by providing their file path:
encrypt_file("keyfile.key", "your-password", "example.txt")The encrypted file is saved with an .enc extension (e.g., example.txt.enc).
Decrypt previously encrypted .enc files:
decrypt_file("keyfile.key", "your-password", "example.txt.enc")The decrypted file is saved without the .enc extension (e.g., example.txt).
- RSA Key Pair: Generates a 4096-bit private and public key pair.
- AES Key: A 256-bit AES key is created and encrypted using the RSA public key.
- Key File Obfuscation: The private key, public key, and encrypted AES key are stored in an obfuscated file secured with an optional password.
- AES Encryption: Data or files are encrypted using the AES key in CFB mode with a random initialization vector (IV).
- RSA Encryption: The AES key is encrypted with the RSA public key and stored for decryption purposes.
- RSA Decryption: The AES key is decrypted using the RSA private key.
- AES Decryption: Encrypted data or files are decrypted using the AES key.
- Enhances AES key security by appending a SHA-256 hash of the key file to the AES key during encryption and decryption.
- RSA 4096-bit Keys: Secure key exchange and AES key protection.
- AES 256-bit Keys: Ensures strong encryption of data.
- Key Obfuscation: Protects sensitive key file contents with Base64 encoding and string reversal.
- File Hashing: Prevents unauthorized modifications by validating key file integrity.
- Error Handling: Gracefully handles missing files, incorrect passwords, and decryption errors.
Contributions are welcome! If you have ideas for improvements or find bugs, feel free to submit an issue or a pull request.
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0). See LICENSE for details.