This is inspired by django-encrypted-fields.
Project description
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.
EncryptedCharFieldEncryptedTextFieldEncryptedDateTimeFieldEncryptedIntegerFieldEncryptedFloatFieldEncryptedEmailFieldEncryptedBooleanFieldEncryptedJSONField
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_fernet_encrypted_fields-0.3.1.tar.gz.
File metadata
- Download URL: django_fernet_encrypted_fields-0.3.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ed328c7f9cc7f2d452bb2e125f3ea2bea3563a259fa943e5a1c626175889a71
|
|
| MD5 |
d169811d8aedce179ca7b98012d9938b
|
|
| BLAKE2b-256 |
1aaa529af3888215b8a660fc3897d6d63eaf1de9aa0699c633ca0ec483d4361c
|
File details
Details for the file django_fernet_encrypted_fields-0.3.1-py3-none-any.whl.
File metadata
- Download URL: django_fernet_encrypted_fields-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bd2abab02556dc6e15a58a61161ee6c5cdf45a50a8a52d9e035009eb54c6442
|
|
| MD5 |
b4cafde9869d3c9e455b70f98e1e53f1
|
|
| BLAKE2b-256 |
527f4e0b7ed8413fa58e7a77017342e8ab0e977d41cfc376ab9180ae75f216ec
|