问题描述
更新:我只知道令牌错误,我不明白使用相同密钥加密和解密时发生了什么? 手头的错误:
Exception in Tkinter callback #Don't understand this callback as this is to do with the cryptography module I am using
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py",line 1883,in __call__
return self.func(*args)
File "/Users/James/Documents/Programming/PasswordManager/main.py",line 190,in see
decrypt = f.decrypt(item[1].encode('utf-8'))
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py",line 75,in decrypt
timestamp,data = Fernet._get_unverified_token_data(token)
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py",line 107,in _get_unverified_token_data
raise InvalidToken
cryptography.fernet.InvalidToken
b'gAAAAABgY3KXoeeegS8RPHdvXTH6_GQ_EPfgdqZqIwP4XL-hIyEk3Bcxv3y0o_quNPFyHeTdkv7Pk9MmnEIL1XeXlEfuUQNJ_e_disAr2ZvLGpDT1Y6I6Qvzat5aAf7Z0624O4BeAFNf
原始问题
我正在制作密码管理器,我从使用文件和一些建议的 sqlite3 开始,所以我开始使用它,以便我可以添加重写密码的功能,但我不断收到两个让我感到困惑的错误,
>表sqlite表:
c.execute("""CREATE TABLE passwords (passwordTitle text,generatedPassword text)""")
def submited():
# Call the password generator
setPassword()
# Get user input from the entry
usrinput = userInput.get()
# Set a splitter for writing to the file
# If passwordenc.txt exists:
if os.path.isfile('data.db'):
# Open passwordenc.txt and set it as password_file
# Encrypt the combo
genPasswordEnc = f.encrypt(generatePassword.encode('utf-8'))
c.execute("INSERT INTO passwords VALUES(?,?)",(usrinput,genPasswordEnc))
conn.commit()
# If passwordenc.txt does not exist:
我用这个函数解密:
def see():
menu.destroy()
seeWin = Tk()
seeWin.geometry('1250x500')
# Same size will be defined in variable for center screen in Tk_Width and Tk_height
Tk_Width = 1250
Tk_Height = 500
# calculate coordination of screen and window form
x_Left = int(seeWin.winfo_screenwidth() / 2 - Tk_Width / 2)
y_Top = int(seeWin.winfo_screenheight() / 2 - Tk_Height / 2)
# Write following format for center screen
seeWin.geometry("+{}+{}".format(x_Left,y_Top))
seeWin.title('See Password')
seeFrame = tk.Frame()
listBox = tk.ListBox(seeFrame,height='30',width='135')
listBox.pack(side=LEFT,fill=BOTH)
scrollbar = tk.Scrollbar(seeFrame,)
scrollbar.pack(side=RIGHT,fill=Y)
listBox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listBox.yview)
if os.path.isfile('data.db'):
c.execute('SELECT * FROM passwords')
password_list = c.fetchall()
for item in password_list:
item = str(item)
itemSplit = item.split(',')
leng = len(itemSplit[1])-2
itemCut = itemSplit[1][:leng].encode('utf-8')
print(itemCut)
decrypt = f.decrypt(itemCut)
print(decrypt)
listBox.insert(END,str(decrypt))
print("Decrypted pass: ",decrypt)
但我不断收到此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py",line 102,in _get_unverified_token_data
data = base64.urlsafe_b64decode(token)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/base64.py",line 133,in urlsafe_b64decode
return b64decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/base64.py",line 87,in b64decode
return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (141) cannot be 1 more than a multiple of 4
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py",in see
decrypt = f.decrypt(itemCut)
File "/Users/James/Documents/Programming/venv/lib/python3.8/site-packages/cryptography/fernet.py",line 104,in _get_unverified_token_data
raise InvalidToken
cryptography.fernet.InvalidToken
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)