Question

Is there any documentation or examples/tutorial how to get EncryptedCharField working in a Django model?

It took me allot of time to install django-extension + keyczar etc in my django project. There is no doc how to get it installed.

This is what got so far:

pip install django-extensions

added 'django_extensions' to INSTALLED_APPS

pip install python-keyczar

created a model + added field with EncryptedCharField

added ENCRYPTED_FIELD_KEYS_DIR = '../../../enc-keys'

downloaded KeyczarTool-0.71g-090613.jar

ran the following command: java -jar KeyczarTool-0.71g-090613.jar create --location=./enc-keys --purpose=crypt --name="first key" --asymmetric=rsa

So far so good, but when I run my server I get the following error:

keyczar.errors.KeyNotFoundError: Key with hash_val identifier None not found.

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.

I can't figure out what I'm doing wrong.

Was it helpful?

Solution

FOUND THE SOLUTION

After create:

  • java -jar KeyczarTool-0.71g-090613.jar addkey --location=./enc-keys --status="primary" --size=2048

OTHER TIPS

FOUND THE SOLUTION WITH OUT JAVA (puach)

try this

bin/keyczart create --location=keys --purpose=crypt --name=models &&     bin/keyczart addkey --location=keys --status=primary

be sure that keys is a folder in your project ,maybe /var/keys ?? or wherever you like

cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top