你能在MySQL表中存储字节(Fernet令牌)吗?python

2024-09-29 01:27:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将这个Fernet加密令牌插入我数据库中的表中。这是一个侦察员的加密医疗信息

b'gAAAAABcIRmX3txIuOrw6FoSxy7I1vorA8hTTzMcXQGwch_jRBtWTsR9TwVyH125K0R6zG-BTvhv_SpZuW-Hs1WotaabBVj5tQ=='

使用此Insert语句

^{pr2}$

在运行时,程序执行,但是insert没有应用到表中,不,我没有忘记mydb.commit()。我相信bytes是MySQL不支持的数据类型,因此无法存储。在这种情况下,我将如何克服这一点,以便能够通过以下方式解密存储的令牌:

Ecy.decrypt(EcryptMedInfo)

Tags: 信息数据库语句insert医疗fernet程序执行pr2
1条回答
网友
1楼 · 发布于 2024-09-29 01:27:35

如果存在b"",并且您希望将其转换为字符串。您应该使用decode()而不是str()。因为如果使用str(),很难将其反转,但是如果使用decode(),则很容易恢复。在

a = b"\x00\x00"
print((a,a.decode(),str(a)))
print(a == a.decode().encode())
#(b'\x00\x00', '\x00\x00', "b'\\x00\\x00'")
#True

When i use mysql.connector, i don't have to transform them into string by myself.

^{pr2}$

I believe that bytes is an unsupported datatype for MySQL and thus cannot be stored.

Mysql可以存储它。Mysql byte array storage

相关问题 更多 >