No description
Find a file
Steven Mapes 9630b3e5e2
Bug fix for #4
This is a bug fix for issue #4 where Django Admin raises an exception when saving Encrypted fields as the value is not encrypted at the time of the clean process.

This PR sets a semaphore property which is checked within the to_python method allowing the decryption to be skipped. It then removes the semaphore property to clean up the field
2021-12-17 17:29:10 +00:00
encrypted_fields Bug fix for #4 2021-12-17 17:29:10 +00:00
package_test Adding in unit tests to test changing the salt but keeping a legacy salt in for reading 2021-12-09 10:01:51 +00:00
.gitignore first commit 2021-09-30 23:27:19 +09:00
.travis.yml first commit 2021-09-30 23:27:19 +09:00
LICENCE.txt first commit 2021-09-30 23:27:19 +09:00
manage.py first commit 2021-09-30 23:27:19 +09:00
README.md Updated README.md with rotating SALT documentation 2021-12-10 11:11:12 +00:00
requirements.txt first commit 2021-09-30 23:27:19 +09:00
setup.py Fix setup.py 2021-12-15 10:09:43 +09:00

Build Status Pypi Package

Django Fernet Encrypted Fields

This package was created as a successor to django-encrypted-fields.

Getting Started

$ pip install django-fernet-encrypted-fields

In your settings.py, set random SALT_KEY

SALT_KEY = '0123456789abcdefghijklmnopqrstuvwxyz'

Then, in models.py

from encrypted_fields.fields import EncryptedTextField

class MyModel(models.Model):
    text_field = EncryptedTextField()

Use your model as normal and your data will be encrypted in the database.

Rotating SALT keys

You can rotate salt keys by turning the SALT_KEY settings.py entry into a list. The first key will be used to encrypt all new data, and decryption of existing values will be attempted with all given keys in order. This is useful for key rotation: place a new key at the head of the list for use with all new or changed data, but existing values encrypted with old keys will still be accessible

SALT_KEY = [
    'zyxwvutsrqponmlkjihgfedcba9876543210',
    '0123456789abcdefghijklmnopqrstuvwxyz'
]

If you wish to update the existing encrypted records simply load and re-save the models to use the new key.

for obj in MuModel.objects.all():
    obj.save()

Available Fields

Currently build in and unit-tested fields. They have the same APIs as their non-encrypted counterparts.

  • EncryptedCharField
  • EncryptedTextField
  • EncryptedDateTimeField
  • EncryptedIntegerField
  • EncryptedFloatField
  • EncryptedEmailField
  • EncryptedBooleanField

Compatible Django Version

Compatible Django Version Specifically tested
2.2 ✔️
3.0 ✔️
3.1 ✔️
3.2 ✔️
4.0 ✔️