This is a collection of Django Model Field classes that are encrypted using PyNaCl.
Project description
Django NaCl Encrypted Fields
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 = b'p1Et2Rb@;^BYdo`ZRFi!Hc-MXu(^|bVqA-FGqffM'
In your settings.py
:
NACL_FIELDS_KEY = b'p1Et2Rb@;^BYdo`ZRFi!Hc-MXu(^|bVqA-FGqffM'
Then, in your models.py
:
from django.db import models
from nacl_encrypted_fields import NaClTextField
class MyModel(models.Model):
text_field = NaClTextField()
Use the model as you would normally and the data will be stored 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.
It is also possible to append the fields key to your settings file automatically upon creation, by using the -f
flag:
python manage.py createkey -f settings.py
Where settings.py
is the path to your settings file.
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 provided NaClFieldMixin
:
from django.db import models
from nacl_encrypted_fields import NaClFieldMixin
class NaClIPAddressField(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
Built Distribution
File details
Details for the file django-nacl-fields-4.0.0.tar.gz
.
File metadata
- Download URL: django-nacl-fields-4.0.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c59a1e44225cdd18fff29399a2814dfbf083e96bfeefc067af445a019e4a0e07 |
|
MD5 | 9965b42ffcaa26c3fff85ca9dd84409c |
|
BLAKE2b-256 | 46028434d84b44ff1c940fcd81a3532aa4f70c2535af7a559a8e5682d0865533 |
File details
Details for the file django_nacl_fields-4.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_nacl_fields-4.0.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adb0f48ff58400cd1a5f1f23767aabd5d8fc71e9a9dd5aa22447f55f2b428f5a |
|
MD5 | e39eed244cb0d18a507b0b1471fe067e |
|
BLAKE2b-256 | 4745d4f3251e82ebb56109b8906089f9d791258334905bf5813d61f88c98ab57 |