首页 > 解决方案 > 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)

标签: djangoencryption

解决方案


推荐阅读