No description
Find a file
2023-07-18 07:15:47 +02:00
.github/workflows moved black to linting job 2022-04-29 13:40:26 +02:00
encrypted_fields Add support for encrypted JSON fields 2023-07-18 06:55:25 +02:00
package_test Add tests that ensure keys are retained, update default arg for json TestModel field 2023-07-18 07:15:47 +02: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
lint-and-test.yml setup github actions with black, flake8, testing and coverage 2022-04-21 14:15:59 +02:00
manage.py setup github actions with black, flake8, testing and coverage 2022-04-21 14:15:59 +02:00
README.md Add support for encrypted JSON fields 2023-07-18 06:55:25 +02:00
requirements.txt first commit 2021-09-30 23:27:19 +09:00
setup.py Fix #10 2022-05-06 09:38:20 +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
  • EncryptedJSONField

Compatible Django Version

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