我正在学习sqlite3
,并尝试将rsa
键插入到我制作的一个列中,但出现以下错误:
sqlite3.InterfaceError: Error binding parameter 2 - probably unsupported type.
这是我的密码:
import sqlite3, rsa
db = sqlite3.connect('database.db')
db.execute('drop table if exists user')
db.execute('create table user (username text, password text, pubKey tuple,
privKey tuple)')
username = input("Input Username: ")
password = input("Input Password: ")
confirm = input("Confirm Password: ")
(pubKey, privKey) = rsa.newkeys(512)
if password == confirm:
db.execute('insert into user (username, password, pubKey, privKey) values (?, ?, ?, ?)', (username, password, pubKey, privKey))
db.commit()
else:
quit()
我正在使用rsa.newkeys密钥生成密钥并生成元组。例如,元组将是以下内容:
公钥(799322577456266985645314739295834657193770213391931749021791221637852796081135316737131739681803403560310318908937895213458133041784535151317298739665537)
我查看了rsa和rsa.newkeys密钥()dpe返回一个元组,但我得到的错误是,它是错误的数据类型。你知道吗
看看你的RSA密钥-它可能是十六进制的(即有数字和字母),所以int不能工作。Int仅用于数字。你知道吗
我建议使用文本或blob作为类型。你知道吗
pubKey和privKey是类的实例(rsa.key.PublicKey密钥以及rsa.key.PrivateKey)你知道吗
从实例中,可以将两个值都取为int:
pubKey.n
-从您的示例来看,它是799322577456266985645314739295834657193770213391931749021791221637285279608041353167371317396818034035603189089378952134581330417845151317298739pubKey.e
-是65537如果只需要密钥,请将int保存到数据库:
如果需要整个字符串,请转换为str并另存为文本:
相关问题 更多 >
编程相关推荐