This project demonstrates the basics of symmetric encryption using Python and the cryptography library. It's a great starting point for beginners interested in cybersecurity, cryptography, or contributing to open-source security tools.
- How to generate secure keys
- How to encrypt and decrypt messages
- Basic key management (saving & loading keys)
- How
Fernet(AES-based encryption) works under the hood
git clone https://github.com/your-username/simple-encryption-python.git
cd simple-encryption-pythonMake sure you have Python 3.6+ installed.
Install required package using pip:
pip install cryptographypython simple_encryption.pyOn first run, it will generate a secret.key file that is used for both encryption and decryption. Each time you run the script, it:
- Loads the existing key
- Encrypts a sample message
- Decrypts it back and displays the result
simple-encryption-python/
│
├── simple_encryption.py # Main script to run encryption and decryption
├── secret.key # Auto-generated AES-based symmetric key (DO NOT SHARE)
├── README.md # Documentation
This example is for educational purposes only. If you’re building a production-grade application:
- Never store raw keys in plaintext
- Use environment variables or secure vaults (e.g., AWS KMS, HashiCorp Vault)
- Handle exceptions and errors securely
-
Fernet is a module in the
cryptographypackage that provides:- AES-128 in CBC mode
- HMAC-SHA256 authentication
- Random IVs for each encryption
-
The encryption key is:
- Generated once and saved to
secret.key - Loaded on subsequent runs
- Generated once and saved to
-
The message is:
- Encrypted using
.encrypt() - Decrypted using
.decrypt()
- Encrypted using
[*] Key loaded from 'secret.key'
Original Message: This is a secret message.
Encrypted Message: b'gAAAAABlZ...'
Decrypted Message: This is a secret message.
Contributions are welcome! You can help by:
- Improving the CLI interface
- Adding file encryption support
- Implementing password-based key derivation
- Writing unit tests
To contribute:
- Fork the repo
- Create a new branch (
git checkout -b my-feature) - Commit your changes
- Push and create a Pull Request
This project is licensed under the MIT License. See LICENSE for details.
Afolabi Adewale
A data and security enthusiast exploring the intersection of Python, encryption, and open-source software.
GitHub Profile