|
| 1 | + |
| 2 | +# 🔐 Simple Symmetric Encryption in Python |
| 3 | + |
| 4 | +This project demonstrates the basics of **symmetric encryption** using Python and the [`cryptography`](https://cryptography.io/en/latest/) library. It's a great starting point for beginners interested in **cybersecurity**, **cryptography**, or contributing to **open-source security tools**. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 📚 What You'll Learn |
| 9 | + |
| 10 | +- How to generate secure keys |
| 11 | +- How to encrypt and decrypt messages |
| 12 | +- Basic key management (saving & loading keys) |
| 13 | +- How `Fernet` (AES-based encryption) works under the hood |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## 🚀 Getting Started |
| 18 | + |
| 19 | +### 1. Clone the Repository |
| 20 | + |
| 21 | +```bash |
| 22 | +git clone https://github.com/your-username/simple-encryption-python.git |
| 23 | +cd simple-encryption-python |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. Install Dependencies |
| 27 | + |
| 28 | +Make sure you have Python 3.6+ installed. |
| 29 | + |
| 30 | +Install required package using `pip`: |
| 31 | + |
| 32 | +```bash |
| 33 | +pip install cryptography |
| 34 | +``` |
| 35 | + |
| 36 | +### 3. Run the Code |
| 37 | + |
| 38 | +```bash |
| 39 | +python simple_encryption.py |
| 40 | +``` |
| 41 | + |
| 42 | +On first run, it will generate a `secret.key` file that is used for both encryption and decryption. Each time you run the script, it: |
| 43 | +- Loads the existing key |
| 44 | +- Encrypts a sample message |
| 45 | +- Decrypts it back and displays the result |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 📂 File Structure |
| 50 | + |
| 51 | +``` |
| 52 | +simple-encryption-python/ |
| 53 | +│ |
| 54 | +├── simple_encryption.py # Main script to run encryption and decryption |
| 55 | +├── secret.key # Auto-generated AES-based symmetric key (DO NOT SHARE) |
| 56 | +├── README.md # Documentation |
| 57 | +``` |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## 🔒 Security Note |
| 62 | + |
| 63 | +This example is for educational purposes only. If you’re building a production-grade application: |
| 64 | +- Never store raw keys in plaintext |
| 65 | +- Use environment variables or secure vaults (e.g., AWS KMS, HashiCorp Vault) |
| 66 | +- Handle exceptions and errors securely |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## 🧠 How It Works (In Brief) |
| 71 | + |
| 72 | +- **Fernet** is a module in the `cryptography` package that provides: |
| 73 | + - AES-128 in CBC mode |
| 74 | + - HMAC-SHA256 authentication |
| 75 | + - Random IVs for each encryption |
| 76 | + |
| 77 | +- The encryption key is: |
| 78 | + - Generated once and saved to `secret.key` |
| 79 | + - Loaded on subsequent runs |
| 80 | + |
| 81 | +- The message is: |
| 82 | + - Encrypted using `.encrypt()` |
| 83 | + - Decrypted using `.decrypt()` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## 💡 Sample Output |
| 88 | + |
| 89 | +``` |
| 90 | +[*] Key loaded from 'secret.key' |
| 91 | +
|
| 92 | +Original Message: This is a secret message. |
| 93 | +Encrypted Message: b'gAAAAABlZ...' |
| 94 | +Decrypted Message: This is a secret message. |
| 95 | +``` |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## 🤝 Contributing |
| 100 | + |
| 101 | +Contributions are welcome! You can help by: |
| 102 | +- Improving the CLI interface |
| 103 | +- Adding file encryption support |
| 104 | +- Implementing password-based key derivation |
| 105 | +- Writing unit tests |
| 106 | + |
| 107 | +To contribute: |
| 108 | +1. Fork the repo |
| 109 | +2. Create a new branch (`git checkout -b my-feature`) |
| 110 | +3. Commit your changes |
| 111 | +4. Push and create a Pull Request |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## 📜 License |
| 116 | + |
| 117 | +This project is licensed under the **MIT License**. See [LICENSE](LICENSE) for details. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## 👨💻 Author |
| 122 | + |
| 123 | +**Afolabi Adewale** |
| 124 | +A data and security enthusiast exploring the intersection of Python, encryption, and open-source software. |
| 125 | +[GitHub Profile](https://github.com/your-username) |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## 🔗 Related Resources |
| 130 | + |
| 131 | +- [Python `cryptography` docs](https://cryptography.io/en/latest/) |
| 132 | +- [Understanding Symmetric vs Asymmetric Encryption](https://www.cloudflare.com/learning/ssl/how-does-ssl-work/) |
| 133 | +- [OWASP Crypto Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html) |
0 commit comments