Note: This is a fork of the official django-cryptography project, which appears to be abandoned. The only change made in this fork that the patch that fixes Django 5 compatibility has been applied and pushed to pypi as a new project.
You can install the forked version from pypi with the following command:
pip install django-cryptography-5
The rest of this README is the original README from the official project.
A set of primitives for easily encrypting data in Django, wrapping the Python Cryptography library. Also provided is a drop in replacement for Django's own cryptographic primitives, using Cryptography as the backend provider.
Do not forget to read the documentation.
Using symmetrical encryption to store sensitive data in the database.
Wrap the desired model field with encrypt
to easily
protect its contents.
from django.db import models
from django_cryptography.fields import encrypt
class MyModel(models.Model):
name = models.CharField(max_length=50)
sensitive_data = encrypt(models.CharField(max_length=50))
The data will now be automatically encrypted when saved to the
database. encrypt
uses an encryption that allows for
bi-directional data retrieval.
- Python (3.7, 3.8, 3.9, 3.10, 3.11)
- Cryptography (2.0+)
- Django (3.2, 4.1, 4.2)
pip install django-cryptography