

With open("secret.key", "wb") as key_file: To generate a key, we call the generate_key() method: from cryptography.fernet import Fernet Encrypt Data in Pythonįirst, we need to install the cryptography library: pip3 install cryptographyįrom the cryptography library, we need to import Fernet and start generating a key - this key is required for symmetric encryption/decryption. The cryptography library that we use here is built on top of AES algorithm. In this example, we will be using symmetric encryption, which means the same key we used to encrypt data, is also usable for decryption. It allows us to securely protect data which we don’t want just anyone to see or access. a string of text using the cryptography library in Python.Įncryption is the process of encoding information in such a way that only authorized parties can access it.


In this tutorial you will learn how to encrypt and decrypt data, e.g.
