Skip to main content

This is inspired by django-encrypted-fields.

Project description

Pypi Package Jazzband

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'
]

Rotating SECRET_KEY

When you would want to rotate your SECRET_KEY, set the new value and put your old secret key value to SECRET_KEY_FALLBACKS list. That way the existing encrypted fields will still work, but when you re-save the field or create new record, it will be encrypted with the new secret key. (supported in Django >=4.1)

SECRET_KEY = "new-key"
SECRET_KEY_FALLBACKS = ["old-key"]

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

for obj in MyModel.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
3.2 :heavy_check_mark:
4.0 :heavy_check_mark:
4.1 :heavy_check_mark:
4.2 :heavy_check_mark:
5.0 :heavy_check_mark:
5.1 :heavy_check_mark:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fernet-encrypted-fields-0.3.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-fernet-encrypted-fields-0.3.0.tar.gz.

File metadata

File hashes

Hashes for django-fernet-encrypted-fields-0.3.0.tar.gz
Algorithm Hash digest
SHA256 38031bdaf1724a6e885ee137cc66a2bd7dc3726c438e189ea7e44799ec0ba9b3
MD5 4d11baf78836044e38fb1a70586544a7
BLAKE2b-256 70b8b6725f1207693ba9e76223abf87eb9e8de5114cccad8ddd1bce29a195273

See more details on using hashes here.

File details

Details for the file django_fernet_encrypted_fields-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_fernet_encrypted_fields-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a17cca5bf3638ee44674e64f30792d5960b1d4d4b291ec478c27515fc4860612
MD5 a5e8a746be303579cee526da086085dd
BLAKE2b-256 758a2c5d88cd540d83ceaa1cb3191ed35dfed0caacc6fe2ff5fe74c9ecc7776f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page