django - Django 如何解密 EncryptedCharField 字段?
问题描述
所以我在我的 Postgres 数据库中有一个字段,它是一个bytea
类型。我知道解密的值和密钥,但不知道如何从原始数据库值获取解密的字符串。我相信我正在寻找 Django 用来解密这些值的算法以及如何使用它来加密另一个字符串。据说 Django 使用包 Keyczar,其中提到使用Crypter
包来加密/解密事物。我无法安装该软件包,所以我不确定如何以另一种方式解决这个问题。
我最终想更新数据库中 EncryptedCharField 字段中的值,因为它不再有效 - 有没有办法在线或在 Python 中获取这个加密值?
添加相关代码。有很多参数和对象被传递,所以希望它不会使遵循下面的代码变得困难:
# How the field is getting read from Postgres:
server_password = EncryptedCharField(null=True, max_length=255)
# Get some other settings info from another table:
settings = SourceSystemSettings.objects.get(school=school, source_system=SourceSystem.objects.VENDOR)
# Setting up the pysftp connection object:
SourceFTP(hosts=[settings.server_host, SERVER_INTERNAL],
user=settings.server_user,
password=settings.server_password,
directory=settings.server_dir)
# Connecting using the password and other settings:
connection = pysftp.Connection(host, username=user, password=password, cnopts=cnopts)
解决方案
推荐阅读
- java - AEM 服务器在本地运行,但 localhost 拒绝连接
- internet-explorer - 在 IE11 上发送密钥后量角器文件上传挂起。适用于 Chrome/Firefox
- javascript - 不在新闻 api 中显示新闻描述
- reactjs - Next js 和 React Framer Motion 未处理的运行时错误
- git - 如何在已经是最新的情况下拉取提交
- netsuite - 在 NetSuite 中,如何使用保存的搜索访问已删除的交易行。请注意我不需要删除的交易记录
- excel - 从 VBA 中的 Excel 验证列表中读取和选择
- sql - SQL Server:在存储过程中的变量中存储多个值
- javascript - react-scroll 不应用滚动视图和链接
- c# - 更改数据库表后更新模型类