# Lock Your Files
# pip install cryptography
from cryptography.fernet import Fernet
# lock Photos
def Lock_Photo(photo):
key = Fernet.generate_key()
f = Fernet(key)
with open(photo, 'rb') as file:
file_data = file.read()
encrypted_data = f.encrypt(file_data)
with open(photo, 'wb') as file:
file.write(encrypted_data)
with open('key.key', 'wb') as key_file:
key_file.write(key)
# unlock Photos
def Unlock_Photo(photo):
with open('key.key', 'rb') as key_file:
key = key_file.read()
f = Fernet(key)
with open(photo, 'rb') as enc_file:
encrypted_data = enc_file.read()
decrypted_data = f.decrypt(encrypted_data)
with open(photo, 'wb') as dec_file:
dec_file.write(decrypted_data)
Lock_Photo('Photo.png')
Unlock_Photo('Photo.png')