我的程序有问题,它所做的只是基于密钥加密和解密文本。但是,当我尝试解密加密的单词时,它只会吐出错误
raise InvalidToken
cryptography.fernet.InvalidToken
这是代码
#Import Libraries
from cryptography.fernet import Fernet
from tkinter import *
import base64
def Encrypt(text_f):
f = Fernet(b'eY_snWFGBTxC55GsmloucJhPtiLt_3bANhHnikOlXFQ=')
print(f.encrypt((str(text_f).encode())))
def Decrypt(text_f):
f = Fernet(b'eY_snWFGBTxC55GsmloucJhPtiLt_3bANhHnikOlXFQ=')
print(f.decrypt((bytes(text_f).encode())))
#Set Window
root = Tk()
#Define Elements
text_user = ""
instruction_1 = Label(root, text="Input Text")
text_input = Entry(root, textvariable=text_user)
button_encode = Button(root, text='Encode', command = lambda : Encrypt(str(text_user.encode())))
button_decode = Button(root, text='Decode', command = lambda : Decrypt(str(text_user.encode())))
text_description = Label(root, text="")
#Pack Elements
instruction_1.pack(ipady = 10, ipadx = 5)
text_input.pack(ipady = 5, ipadx = 4)
button_encode.pack(ipady = 3, ipadx = 12)
button_decode.pack(ipady = 3, ipadx = 12)
#Setup Window Properties
root.geometry('800x650')
root.title("APEP | Encoder & Decoder")
#Loop Window Runtime
root.mainloop()