Fernet (symmetric encryption)

Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key.

Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key. Fernet is an implementation of symmetric (also known as ‘secret key’) authenticated cryptography. Fernet also has support for implementing key rotation via MultiFernet.

!pip install cryptography

Code

from cryptography.fernet import Fernet

my_secret = b'my deep dark secret'

key = Fernet.generate_key()
cipher_suite = Fernet(key)

cipher_text = cipher_suite.encrypt(my_secret)
plain_text = cipher_suite.decrypt(cipher_text)

print("The ciphertext is: {}".format(cipher_text))
print("The plaintext is.: {}".format(plain_text))

Output

The ciphertext is: b'gAAAAABe8-LW_HKdLKQ3RtNpjLFFzo02TnyaVACgSuO56JoE06onY1avgxJsaaQmE40hLJC28m_NNZF9gtBQis_eTycN7rUe_G57VvDFLwC_83N3uR4ROBE='
The plaintext is.: b'my deep dark secret'

Adapted by: tutorialspoint

Sérgio Mendonça
Sérgio Mendonça
Professor of Computer Science

My research interests include the Internet of Things, Blockchain and Cryptocurrencies, Cryptography and Network Security, Computer Simulations, and Programming.

comments powered by Disqus

Related