微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我不断收到 base64 和令牌错误这是什么意思?

如何解决我不断收到 base64 和令牌错误这是什么意思?

更新:我只知道令牌错误,我不明白使用相同密钥加密和解密时发生了什么? 手头的错误

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

我不明白在使用 .txt 文件时是什么引发了这个错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。