from cryptography.fernet import Fernet key = Fernet.generate_key() print(key)
from cryptography.fernet import Fernet key = b'yourkeyhere' cipher = Fernet(key) message = b'secret message' encrypted_message = cipher.encrypt(message) print(encrypted_message) decrypted_message = cipher.decrypt(encrypted_message) print(decrypted_message)This code uses a pre-existing key to encrypt and decrypt a message. The key is passed into the Fernet() function and a cipher is created. The message is then encrypted using the encrypt() function and decrypted using the decrypt() function. The package library for cryptography.fernet is 'cryptography'. This library must be installed using pip before using the Fernet functions.