好的,所以我正在尝试在 python 中编写密码管理器,我正在使用 cyrptography.fernet 来加密电子邮件和密码,然后将它们存储到本地 SQLite 数据库中,问题是当我尝试获取例如电子邮件时它们采用这种格式的数据库: (b'encypted-email-here'), (b'and-so-on) 所以我认为既然引号之前的 b 是字节格式,我不需要做任何事情为了解密它们,但是当我实际尝试解密它们时,我收到一条错误消息:“TypeError:token must be bytes”这是我的代码,因此您可以查看一下
b_email = email.encode('utf-8')
b_pwd = pwd.encode('utf-8')
enc_email = f.encrypt(b_email)
enc_pwd = f.encrypt(b_pwd)
conn = sqlite3.connect('database.db')
execute = conn.cursor()
execute.execute('CREATE TABLE IF NOT EXISTS logins (website, email, password)')
execute.execute('INSERT INTO logins VALUES (:website, :email, :password)', {'website': website, 'email': enc_email, 'password': enc_pwd})
conn.commit()
conn.close()
def view():
con = sqlite3.connect('database.db')
cur = con.cursor()
iterable = cur.execute('SELECT email FROM logins')
for email in iterable:
dec_email = f.decrypt(email)
print(dec_email)```