django-nacl-fields


Namedjango-nacl-fields JSON
Version 4.1.0 PyPI version JSON
download
home_pagehttps://github.com/warpnet/django-nacl-fields
SummaryThis is a collection of Django Model Field classes that are encrypted using PyNaCl.
upload_time2022-12-27 16:58:08
maintainer
docs_urlNone
authorWarpnet B.V.
requires_python
licenseApache License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django NaCl Encrypted Fields

![GitHub Actions: test](https://github.com/warpnet/django-nacl-fields/workflows/test/badge.svg)
![GitHub Actions: lint](https://github.com/warpnet/django-nacl-fields/workflows/lint/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/django-nacl-fields/badge/?version=latest)](https://django-nacl-fields.readthedocs.io/en/latest/?badge=latest)

This is a collection of Django Model Field classes that are encrypted using PyNaCl. This package is largely based on [django-encrypted-fields](https://github.com/defrex/django-encrypted-fields), which makes use of the outdated Keyczar library to encrypt fields. Besides that, it is inspired by [django-fernet-field](https://github.com/orcasgit/django-fernet-fields).


## About PyNaCl

[PyNaCl](https://github.com/pyca/pynacl) is a Python binding to [libsodium](https://github.com/jedisct1/libsodium), which is a fork of the [Networking and Cryptography library](https://nacl.cr.yp.to). These libraries have a stated goal of improving usability, security and speed.


## Getting Started

Install `django-nacl-fields`:
```sh
pip install django-nacl-fields
```

Add `nacl_encrypted_fields` to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = [
    ...
    'nacl_encrypted_fields'
    ...
]
```

Create a key to be used for encryption:
```sh
$ 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`:
```python
NACL_FIELDS_KEY = b'p1Et2Rb@;^BYdo`ZRFi!Hc-MXu(^|bVqA-FGqffM'
```

Then, in your `models.py`:
```python
from django.db import models
from nacl_encrypted_fields.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:
```sh
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`
- `NaClJSONField`


## Encrypt Your Own Fields

Making new fields can be done by using the provided `NaClFieldMixin`:
```python
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.

## Contributing

Start a PostgreSQL Docker container for testing using:
```bash
docker run --rm -e POSTGRES_PASSWORD=postgres POSTGRES_DB=github_actions postgres
```

Then, you can run tests in another window using:
```bash
python -m venv env
source env/bin/activate
pip install '.[test]'
python manage.py test
```

Before you contribute, make sure you lint your code:
```bash
pip install '.[lint]'
flake8 --exclude .git,pycache,docs/conf.py,build,dist,env
```

After you code is done, free free to open a new pull request.

## References

- <https://github.com/defrex/django-encrypted-fields>
- <https://github.com/orcasgit/django-fernet-fields>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/warpnet/django-nacl-fields",
    "name": "django-nacl-fields",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Warpnet B.V.",
    "author_email": "info@warpnet.nl",
    "download_url": "https://files.pythonhosted.org/packages/91/03/c5ff45a1cb1bff266f7a58d72574059c32e8c49263963d1cbb5d60c49712/django-nacl-fields-4.1.0.tar.gz",
    "platform": null,
    "description": "# Django NaCl Encrypted Fields\n\n![GitHub Actions: test](https://github.com/warpnet/django-nacl-fields/workflows/test/badge.svg)\n![GitHub Actions: lint](https://github.com/warpnet/django-nacl-fields/workflows/lint/badge.svg)\n[![Documentation Status](https://readthedocs.org/projects/django-nacl-fields/badge/?version=latest)](https://django-nacl-fields.readthedocs.io/en/latest/?badge=latest)\n\nThis is a collection of Django Model Field classes that are encrypted using PyNaCl. This package is largely based on [django-encrypted-fields](https://github.com/defrex/django-encrypted-fields), which makes use of the outdated Keyczar library to encrypt fields. Besides that, it is inspired by [django-fernet-field](https://github.com/orcasgit/django-fernet-fields).\n\n\n## About PyNaCl\n\n[PyNaCl](https://github.com/pyca/pynacl) is a Python binding to [libsodium](https://github.com/jedisct1/libsodium), which is a fork of the [Networking and Cryptography library](https://nacl.cr.yp.to). These libraries have a stated goal of improving usability, security and speed.\n\n\n## Getting Started\n\nInstall `django-nacl-fields`:\n```sh\npip install django-nacl-fields\n```\n\nAdd `nacl_encrypted_fields` to your `INSTALLED_APPS`:\n```python\nINSTALLED_APPS = [\n    ...\n    'nacl_encrypted_fields'\n    ...\n]\n```\n\nCreate a key to be used for encryption:\n```sh\n$ python manage.py createkey\n# put the following line in your settings.py:\nNACL_FIELDS_KEY = b'p1Et2Rb@;^BYdo`ZRFi!Hc-MXu(^|bVqA-FGqffM'\n```\n\nIn your `settings.py`:\n```python\nNACL_FIELDS_KEY = b'p1Et2Rb@;^BYdo`ZRFi!Hc-MXu(^|bVqA-FGqffM'\n```\n\nThen, in your `models.py`:\n```python\nfrom django.db import models\nfrom nacl_encrypted_fields.fields import NaClTextField\n\n\nclass MyModel(models.Model):\n    text_field = NaClTextField()\n```\n\nUse the model as you would normally and the data will be stored encrypted in the database.\n\n**Note:** Encrypted data cannot be used to query or sort. In SQL, these will all look like text fields with random text.\n\nIt is also possible to append the fields key to your settings file automatically upon creation, by using the `-f` flag:\n```sh\npython manage.py createkey -f settings.py\n```\n\nWhere `settings.py` is the path to your settings file.\n\n\n## Available Fields\n\nCurrently build-in and unit-tested fields.\n\n- `NaClCharField`\n- `NaClTextField`\n- `NaClDateTimeField`\n- `NaClIntegerField`\n- `NaClFloatField`\n- `NaClEmailField`\n- `NaClBooleanField`\n- `NaClJSONField`\n\n\n## Encrypt Your Own Fields\n\nMaking new fields can be done by using the provided `NaClFieldMixin`:\n```python\nfrom django.db import models\nfrom nacl_encrypted_fields import NaClFieldMixin\n\n\nclass NaClIPAddressField(NaClFieldMixin, models.IPAddressField):\n    pass\n```\n\nPlease report any issues you encounter when trying this.\n\n## Contributing\n\nStart a PostgreSQL Docker container for testing using:\n```bash\ndocker run --rm -e POSTGRES_PASSWORD=postgres POSTGRES_DB=github_actions postgres\n```\n\nThen, you can run tests in another window using:\n```bash\npython -m venv env\nsource env/bin/activate\npip install '.[test]'\npython manage.py test\n```\n\nBefore you contribute, make sure you lint your code:\n```bash\npip install '.[lint]'\nflake8 --exclude .git,pycache,docs/conf.py,build,dist,env\n```\n\nAfter you code is done, free free to open a new pull request.\n\n## References\n\n- <https://github.com/defrex/django-encrypted-fields>\n- <https://github.com/orcasgit/django-fernet-fields>\n",
    "bugtrack_url": null,
    "license": "Apache License",
    "summary": "This is a collection of Django Model Field classes that are encrypted using PyNaCl.",
    "version": "4.1.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "899a0751dfcf77626178e37efa9b148b",
                "sha256": "2412d4cec7c2034ffafa6a048a4ac5f0a81b401680b0ff4da801d32c2b159f28"
            },
            "downloads": -1,
            "filename": "django_nacl_fields-4.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "899a0751dfcf77626178e37efa9b148b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12947,
            "upload_time": "2022-12-27T16:58:07",
            "upload_time_iso_8601": "2022-12-27T16:58:07.436995Z",
            "url": "https://files.pythonhosted.org/packages/c7/9d/e25bb27b4bd84e38d3d99537548e724fe4d475ad12131fe18fdd21b2064b/django_nacl_fields-4.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "b55b1390601b43d65f64c8dc8b621e0d",
                "sha256": "81e8426e0008ab94e98457677b68b6478b85d210a06c1e82de8c46dffcac5170"
            },
            "downloads": -1,
            "filename": "django-nacl-fields-4.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b55b1390601b43d65f64c8dc8b621e0d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14455,
            "upload_time": "2022-12-27T16:58:08",
            "upload_time_iso_8601": "2022-12-27T16:58:08.781416Z",
            "url": "https://files.pythonhosted.org/packages/91/03/c5ff45a1cb1bff266f7a58d72574059c32e8c49263963d1cbb5d60c49712/django-nacl-fields-4.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-27 16:58:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "warpnet",
    "github_project": "django-nacl-fields",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-nacl-fields"
}
        
Elapsed time: 0.05122s