我正在尝试从 mysql 中选择 fernet 加密密码并对其进行解密,但是当我执行代码时出现以下错误:
raise InvalidToken
cryptography.fernet.InvalidToken
这是我的功能,我在这里选择数据,然后在没有“)”“]”等的情况下使其看起来不错,然后我将其转换为字节并尝试解密:
def select():
email = entry1.get()
print(email)
passw = entry2.get()
print(passw)
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="camp"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT password FROM campuser WHERE username =%s", (email,))
myresult = mycursor.fetchall()
resu = str(myresult)
resusplit = resu.split(",")[0]
resurep = resusplit.replace("[(", "").replace("'", "").replace(")]", "")
passwnc= resurep
passwbyte = bytes(passwnc, 'utf-8')
print(a)
if(message==myresult):
print("ok")
for x in myresult:
print(x)
def decrypt():
f = Fernet(key)
decrypted = f.decrypt(passwbyte) # Decrypt the bytes. The returning object is of type bytes
text=bytes(decrypted).decode("utf-8")
print(text)
decrypt()