Skip to main content

This is a collection of Django Model Field classes that are encrypted using PyNaCl.

Project description

Build Status Read the Docs (version)

This is a collection of Django Model Field classes that are encrypted using PyNaCl. This package is largely based on django-encrypted-fields, which makes use of the outdated Keyczar library to encrypt fields. Besides that, it is inspired by django-fernet-field.

About PyNaCl

PyNaCl is a Python binding to libsodium, which is a fork of the Networking and Cryptography library. These libraries have a stated goal of improving usability, security and speed.

Getting Started

~ pip install django-nacl-fields

Create a key to be used for encryption.

~ python manage.py createkey
# put the following line in your settings.py:
NACL_FIELDS_KEY = 'cGa9QJDY/FJhbITXHnrIqlgyeLDS04/WqWtgqPEIU4A='

In your settings.py (or append it automatically after generation using the -f flag)

NACL_FIELDS_KEY = 'cGa9QJDY/FJhbITXHnrIqlgyeLDS04/WqWtgqPEIU4A='

Then, in your models.py

from django.db import models
from nacl_encrypted_fields import NaClTextField


class MyModel(models.Model):
        text_field = NaClTextField()

Use your model as normal and your data will be encrypted in the database.

Note: Encrypted data cannot be used to query or sort. In SQL, these will all look like text fields with random text.

Available Fields

Currently build in and unit-tested fields.

  • NaClCharField

  • NaClTextField

  • NaClDateTimeField

  • NaClIntegerField

  • NaClFloatField

  • NaClEmailField

  • NaClBooleanField

Encrypt Your Own Fields

Making new fields can be done by using the build-in NaClFieldMixin:

from django.db import models
from nacl_encrypted_fields import NaClFieldMixin

class EncryptedIPAddressField(NaClFieldMixin, models.IPAddressField):
        pass

Please report any issues you encounter when trying this.

References

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-nacl-fields-1.0.1.tar.gz (12.9 kB view details)

Uploaded Source

File details

Details for the file django-nacl-fields-1.0.1.tar.gz.

File metadata

  • Download URL: django-nacl-fields-1.0.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for django-nacl-fields-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8d48e837cf982f28698be9f5e457752a5e1d846c64d93405ba53ad708d8b9a13
MD5 58943fed591909cf706f3c82362d3cde
BLAKE2b-256 32e545339c6d4a23c9d3d6616a42fbdfe8ac8344d3b33e646ee260b3afd32a49

See more details on using hashes here.

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