是否有任何文档或示例/教程如何让 EncryptedCharField 在 Django 模型中工作?
我花了很多时间在我的 django 项目中安装 django-extension + keyczar 等。没有文档如何安装它。
这是到目前为止的结果:
pip 安装 django 扩展
将“django_extensions”添加到 INSTALLED_APPS
pip 安装 python-keyczar
创建模型 + 使用 EncryptedCharField 添加字段
添加了 ENCRYPTED_FIELD_KEYS_DIR = '../../../enc-keys'
下载KeyczarTool-0.71g-090613.jar
运行以下命令:java -jar KeyczarTool-0.71g-090613.jar create --location=./enc-keys --purpose=crypt --name="第一个 key "--asymmetric=rsa
到目前为止一切顺利,但是当我运行我的服务器时出现以下错误:
keyczar.errors.KeyNotFoundError:未找到带有 hash_val 标识符的 key 。
TRACEBACK
File "/Users/nv/Projects/project/models/client.py", line 78, in <module>
class Authorization(models.Model):
File "/Users/nv/Projects/project/models/client.py", line 86, in Authorization
iban_enc = EncryptedCharField(max_length=155)
File "/Users/nv/Projects/project/lib/python2.7/site-packages/django_extensions/db/fields/encrypted.py", line 121, in __init__
super(EncryptedCharField, self).__init__(*args, **kwargs)
File "/Users/nv/Projects/project/lib/python2.7/site-packages/django_extensions/db/fields/encrypted.py", line 32, in __init__
max_length = len(self.prefix) + len(self.crypt.Encrypt('x' * max_length))
File "/Users/nv/Projects/project/lib/python2.7/site-packages/keyczar/keyczar.py", line 338, in Encrypt
encrypting_key = self.primary_key
File "/Users/nv/Projects/project/lib/python2.7/site-packages/keyczar/keyczar.py", line 73, in <lambda>
primary_key = property(lambda self: self.GetKey(self.primary_version),
File "/Users/nv/Projects/project/lib/python2.7/site-packages/keyczar/keyczar.py", line 128, in GetKey
raise errors.KeyNotFoundError(key_id)
keyczar.errors.KeyNotFoundError: Key with hash_val identifier None not found.
我不知道我做错了什么。
最佳答案
找到解决方案
创建后:
- java -jar KeyczarTool-0.71g-090613.jar addkey --location=./enc-keys --status="primary"--size=2048
关于django-extensions - 如何使用加密字符字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19951095/