from cryptography.fernet import Fernet
import json
def encrypt_file(file_path: str, key: str):
"""Encrypt a file using a symmetric key."""
# load the file
with open(file_path, 'r') as file:
data = json.load(file)
# convert the dictionary into a string
data_string = json.dumps(data, sort_keys=True)
# create a Fernet object
fernet = Fernet(key)
# encrypt and return the data
encrypted_data = fernet.encrypt(data_string.encode())
return encrypted_data
# generate a symmetric key
key = Fernet.generate_key()
# encrypt the file
encrypted_data = encrypt_file('security.json', key)