通过 SQLALchemy 在 Postgres 中插入加密数据

发布于 2024-09-15 12:20:04 字数 223 浏览 5 评论 0原文

我想使用 RSA 算法加密一个字符串,然后使用 python 中的 SQLAlchemy 将该字符串存储到 postgres 数据库中。然后检索加密的字符串并使用相同的密钥对其进行解密。我的问题是存储在数据库中的值与实际的加密字符串不同。存储加密值的列的数据类型是bytea。我正在使用 pycrypto 库。在将数据插入数据库表之前,是否需要更改特定格式的数据?

有什么建议请。

谢谢, 塔拉·辛格

I want to encrypt a string using RSA algorithm and then store that string into postgres database using SQLAlchemy in python. Then Retrieve the encrypted string and decrypt it using the same key. My problem is that the value gets stored in the database is not same as the actual encrypted string. The datatype of column which is storing the encrypted value is bytea. I am using pycrypto library. Do I need to change the data in a particular format before inserting it to database table?

Any suggestions please.

Thanks,
Tara Singh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-09-22 12:20:04

“同一键”您的意思是“另一个键”,对吗? RSA 给你一个密钥对,如果你用一个密钥对加密,你用另一个密钥对解密......

除此之外,这听起来像是一个编码问题。尝试将数据存储为二进制或使用数据库排序规则对字符串进行编码。

基本上,加密为您提供字节,但您将它们存储为字符串(编码字节)。

By "same key" you mean "the other key", right? RSA gives you a keypair, if you encrypt with one you decrypt with the other ...

Other than that, it sounds like a encoding problem. Try storing the data as binary or encode the string with your databases collation.

Basically encryption gives you bytes but you store them as a string (encoded bytes).

等风也等你 2024-09-22 12:20:04

我认为 SQLAlchemy 文档包含一个使用“混合”属性的“配方”示例。我并不声称完全理解它或尝试过它,但您可能会发现它很有用:

http ://www.sqlalchemy.org/trac/wiki/UsageRecipes/SymmetricEncryption

I think the SQLAlchemy documents contain a 'recipe' example which uses the 'hybrid' property. I do not profess to understand it fully or tried it yet, but you may find it useful:

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SymmetricEncryption

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文