3

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.

nelsonvarela
  • 2,310
  • 7
  • 27
  • 43

2 Answers2

5

FOUND THE SOLUTION

After create:

  • java -jar KeyczarTool-0.71g-090613.jar addkey --location=./enc-keys --status="primary" --size=2048
nelsonvarela
  • 2,310
  • 7
  • 27
  • 43
  • 1
    If you used keyczar in python with django why you didn't use the python tool? 'keyczart create --location=keys --purpose=crypt --asymmetric=rsa' and 'keyczart addkey --location=keys --purpose=crypt --size=2048 --status=primary'? – diegueus9 Jun 05 '15 at 20:32
  • Just did my comment because the size option is not mandatory and some times is a problem in old apps :) cheers – mullerivan May 10 '16 at 21:47
1

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

mullerivan
  • 1,833
  • 1
  • 14
  • 15