【发布时间】:2021-04-21 08:29:11
【问题描述】:
正在使用“密码保护程序”并将使用模块“密码学”来加密密码。我还需要将您从密码学生成的密钥保存在数据库中,但我不确定您实际上是如何做到这一点的。
自己做了一些谷歌搜索,它似乎被称为“字节字符串”?虽然不太确定它是什么。
这是我目前拥有的:
from cryptography.fernet import Fernet
import mysql.connector
db = mysql.connector.connect(
host='localhost',
user='root',
password='',
database='password_saver'
)
cursor = db.cursor()
key = Fernet.generate_key()
cursor.execute(f"INSERT INTO `encryption`(`encryption_key`) VALUES ({key})")
使用该代码,我收到此错误:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b'cryptographys key is here')' at line 1
不确定是否有特定的数据类型需要用于 SQL,或者是否需要在 python 中执行?
【问题讨论】:
标签: python sql python-3.x mariadb