This project is an exploration of the pyca/cryptography library, specifically focusing on symmetric encryption using Fernet. It demonstrates how to securely generate, store, use, and manage encryption keys, as well as encrypt and decrypt messages.
- Key Generation: Generate a key and save it to a file for later use.
- Message Encryption: Encrypt sensitive data using the saved key.
- Message Decryption: Decrypt encrypted data using the same key.
To run this project, you'll need:
- Python 3.6 or higher
cryptography
library
You can install the required library using the following command:
pip install cryptography
The project consists of three Python files:
-
generate_key.py
:- Generates a Fernet key and saves it in a file (
secret.key
). - Run this script first to create the key for encryption and decryption.
- Generates a Fernet key and saves it in a file (
-
encrypt_message.py
:- Loads the key from the
secret.key
file and encrypts a message. - The encrypted message (token) is displayed.
- Loads the key from the
-
decrypt_message.py
:- Loads the key from the
secret.key
file and decrypts the encrypted message (token). - The original message is displayed.
- Loads the key from the
-
Clone the Repository
git clone https://github.com/LahcenEzzara/pyca-cryptography-explorer.git cd pyca-cryptography-explorer
-
Generate a Key
Run the
generate_key.py
script to generate a new encryption key and save it tosecret.key
:python generate_key.py
-
Encrypt a Message
Use the
encrypt_message.py
script to encrypt a message:python encrypt_message.py
The script will display the encrypted message (token).
-
Decrypt a Message
To decrypt the encrypted message, run the
decrypt_message.py
script and replaceYOUR_ENCRYPTED_TOKEN_HERE
in the script with the encrypted token:python decrypt_message.py
The original message will be displayed.
- Always keep the encryption key (
secret.key
) secure. Anyone with access to this key can decrypt your encrypted data. - Never share the key publicly or commit it to version control.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy exploring the pyca/cryptography library!