How to encrypt and decrypt text using MultiFernet module in python?


To see the encryption and decryption of a given text message using MultiFernet module in python.

Fernet (symmetric encryption):

  • Fernet guarantees that a message
    encrypted using it  cannot be
    manipulated or read without
    the key.
  • Its imported from cryptography
    library in python.
  • Its implementation of symmetric
    authenticated  cryptography
    (also known as secret key).

#import Fernet and MultiFernet
from cryptography.fernet import Fernet, MultiFernet
#Generate MultiFernet key
key1 = Fernet(Fernet.generate_key())
key2 = Fernet(Fernet.generate_key())
Multikey = MultiFernet([key1, key2])
print(“Actual message is:FirstSoft Technologies Pvt Ltd”)

#Encrypt the message
encode = Multikey.encrypt(b”FirstSoft Technologies Pvt Ltd”)
print(“The encrypted message is:\n”,encode)

#Decrypt the message
decode = Multikey.decrypt(encode)
print(“The decrypted message is:\n”,decode)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit