I want to make it so that I can write any text, then encrypt it and generate a key with which I can get the already decrypted text!
I found a guide, but I can’t figure out how to make a comparison, that if the key is correct, it gives me a decrypted message, if it’s wrong, an error
Guide Link: https://nitratine.net/blog/post/encryption-and-decryption-in-python/#what-is-symmetric-encryption
from cryptography.fernet import Fernet
from tkinter import *
window = Tk()
window.geometry("300x300")
lbl0 = Label(window, text="Enter the key")
lbl0.pack(pady=10)
ent = Entry()
ent.pack()
lbl1 = Label(window, text="Result:")
lbl1.pack(pady=10)
lbl2 = Label(window, text="")
lbl2.pack(pady=10)
global key
def write_key():
key = Fernet.generate_key()
with open("key.key", "wb") as key_file:
key_file.write(key)
def load_key():
return open("key.key", "rb").read()
def generate():
message = ent.get().encode()
write_key()
key = load_key()
f = Fernet(key)
def compare():
if key == ent.get():
print("Success")
else:
print("Fail")
btn1 = Button(text="generate", command=generate)
btn1.pack()
btn2 = Button(text="compare", command=compare)
btn2.pack()
window.mainloop()