Skip to main content

Symmetric encryption for model fields in Django

Project description

build-and-tests

Django Symmetric Fields

This package provides encrypted model fields in Django using symmetric fernet encryption.

Getting started

Package installation

$ pip install django-symmetric-fields

Keys

django-symmetric-fields uses fernet keys from settings.py for encryption. Provide a list of keys in the DSF_ENCRYPTION_KEYS setting. E.g:

DSF_ENCRYPTION_KEYS = [
    b"key1",
    b"key2",
]

Package supports key rotation. A newest key in the front of the list is used to encrypt new data, while the later ones assure that the old encrypted data can still be read.

Usage

After you've completed the initial installation and provided keys in settings.py you can import your new fernet fields like any other:

from symmetricfields.fields import FernetEncryptedTextField

class ModelWithEncryptedField(models.Model):
    encrypted_field = FernetEncryptedTextField()

Retrieving values

Each field is provided with two properties used to retrieve the values of the fields value and decrypt. The values are not decrypted until explicitly requested.

ModelWithEncryptedField.objects.create(encrypted_field='test')

my_new_encrypted_object = ModuleWithEncryptedField.objects.first()
my_new_encrypted_object.encrypted_field.value  # returns encrypted value of the field
my_new_encrypted_object.encrypted_field.decrypt  # returns 'test'

Supports

python >= 3.7, django>=2.0

requires cryptography >= 0.9

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-symmetric-fields-0.0.3.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

django_symmetric_fields-0.0.3-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

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