SEC-13
SEC-13
The Program:
key = Fernet.generate_key()
mykey.write(key)
key = mykey.read()
# encrypt file
f = Fernet(key)
original = original_file.read()
encrypted = f.encrypt(original)
encrypted_file.write(encrypted)
1|Page Cyber Security Lab Manual – KAMALAKAR HEGDE
# To see encrypted file contents
file1 = open("encrypted_tips.txt","r+")
print(file1.read())
print()
#decrypt file
encrypted = encrypted_file.read()
decrypted = f.decrypt(encrypted)
decrypted_file.write(decrypted)
file1 = open("decrypted_tips.txt","r+")
print(file1.read())
print()
OUTPUT:
gAAAAABlcpnUdEBoWdj--fmzEKeEGwz6pvrtcAJh-
25aIWuPNjQ3zddHr3ZE1SORGMX3OOfaynplPsSCF-
TwcUrEDwUaTBMTOswrn31umMVSS_NpP9y2WIhug4lgKNJJ1cPs-
2|Page Cyber Security Lab Manual – KAMALAKAR HEGDE
WJjU0chmmSN1JfOrjgUIwDcELC1JeF6dwECWRMPYtArWsyaVDyDVbkiG4LDiIFsrz2
ciUI-LZGzX_RAWBgrl3aKjrHEnYfNOZNvxesUu_v87GyQBfeeR5iufkt82Xj0JyEXPFok
user2,password
user3,password123
user4,password123$
user5,Password6#(%
user6,Germany#12
user7,USA12^$#
user8,England0#
Fernet
Fernet is a symmetric encryption technique available to users in the cryptography module in
Python that makes it easy to encrypt and decrypt text and provides an easy interface for
beginners in cryptography.
Fernet uses the Advanced Encryption Standard (AES) algorithm to encode and decode
messages. AES is a highly secure, widely used and popular cryptography algorithm used by
developers.
The cipher texts of Fernet are URL-safe, which means, we can send the cipher texts through the
World Wide Web, making data transmission more convenient.
Fernet generates a highly secure alphanumeric key using a random number generator. It is a
32-byte long key, making it highly resistant to brute-force attacks.
It also supports key rotation, that is, the ability to generate new keys and replace the old keys
all the time.
Fernet supports time stamping and serialization of data to be attached along with the key. This
is done in order to improve the security of the key since attaching a timestamp to the key will
ensure that it has limited validity.