first post here, as to not waste your time, lets get right into it: Is it possible to give a key generated by the cryptography.fernet module a name that is a earlier defined variable? Example:
# import required module
import os
from cryptography.fernet import Fernet
from tkinter import *
from tkinter.filedialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filepath = askopenfilename() # show an "Open" dialog box and return the path to the selected file
var1 = (os.path.basename(filepath)) # cuts the filepath into a filename
# key generation
key = Fernet.generate_key()
# string the key in a file
with open('filekey.key','wb') as filekey:
filekey.write(key)
# opening key
with open('filekey.key', 'rb') as filekey:
key = filekey.read()
# using the generated key
fernet = Fernet(key)
# opening the original file to encrypt
with open(filepath, 'rb') as file:
original = file.read()
# encrypting the file
encrypted = fernet.encrypt(original)
# opening the file in write mode and
# writing the encrypted data
with open(filepath, 'wb') as encrypted_file:
encrypted_file.write(encrypted)
My goal is to give the generated key the output of the var1 variable as a name.