Skip to main content

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

To generate a new SECRET_KEY, you can use Django's get_random_secret_key function.

from django.core.management.utils import get_random_secret_key

new_secret_key = get_random_secret_key()
print(new_secret_key)

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 built-in and unit-tested fields include the following. 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 Python Version Required
3.2 3.8+
4.0 3.8+
4.1 3.8+
4.2 :heavy_check_mark: 3.8+
5.0 3.10+
5.1 :heavy_check_mark: 3.10+
5.2 :heavy_check_mark: 3.10+
6.0 :heavy_check_mark: 3.12+

Contributing

See CONTRIBUTING.md for details on how to contribute to this project.

Metadata

Release files for django-fernet-encrypted-fields 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-fernet-encrypted-fields 0.4.0
File Size Uploaded
django_fernet_encrypted_fields-0.4.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-fernet-encrypted-fields 0.4.0
File Interpreter ABI Platform
django_fernet_encrypted_fields-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / django_fernet_encrypted_fields-0.4.0.tar.gz

Download URL django_fernet_encrypted_fields-0.4.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
836c927a260a834a35c4caecf82a97a5e411408cbecb44e25caddd02d8cdd86e
BLAKE2b-256 checksum
How to use checksums
95d7df0426ebf5b1784d064825ec8e5940e634991452066cfacc7fe0138f091a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.6

Release files / django_fernet_encrypted_fields-0.4.0-py3-none-any.whl

Download URL django_fernet_encrypted_fields-0.4.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3e4049882b8c7216d868b7aa7533e466a48c1307b5d4b1b8dc4cb5946d87eec
BLAKE2b-256 checksum
How to use checksums
8375c6de2333c26d0052d2175bf21dc3f5c45e878090946a75fb0c827da6e40a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

1 release file

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page