Save field value encrypted to database.
Project description
django-safe-fields
Save field value encrypted to database.
Install
pip install django-safe-fields
Shipped Fields
Mixins
- SafeFieldMixinBase
- SafeStringFieldMixin
- SafeIntegerFieldMixin
Fields
- SafeCharField
- SafeTextField
- SafeEmailField
- SafeURLField
- SafeGenericIPAddressField
- SafeIntegerField
Note
- Default cipher is aes-128-ecb. It keeps the same with mysql's aes_encrypt and aes_decrypt when server variable block_encryption_mode=aes-128-ecb.
- Default password is settings.SECRET_KEY, but we STRONGLY suggest you use different password for every different field.
Usage
pro/settings.py
INSTALLED_APPS = [
...
'django_safe_fields',
...
]
- Insert
django_safe_fields
into INSTALLED_APPS.
app/models.py
from django.db import models
from django.conf import settings
from django_safe_fields.fields import SafeCharField
from django_safe_fields.fields import SafeGenericIPAddressField
from django_safe_fields.fields import SafeIntegerField
from fastutils.cipherutils import S12Cipher
from fastutils.cipherutils import HexlifyEncoder
class Account(models.Model):
username = SafeCharField(max_length=64)
name = SafeCharField(max_length=64, cipher_class=S12Cipher)
email = SafeCharField(max_length=128, null=True, blank=True, cipher=S12Cipher(password=settings.SECRET_KEY, encoder=HexlifyEncoder(), force_text=True))
last_login_ip = SafeGenericIPAddressField(max_length=256, null=True, blank=True, password="THIS FIELD PASSWORD")
level = SafeIntegerField(null=True, blank=True)
def __str__(self):
return self.username
- All fields will be stored with encryption.
- AesCipher is a strong cipher.
- With aes encryption, you can NOT search partly, only the
exact
search rule will be accepted. - With aes encryption, you can NOT sort.
- S12Cipher is a week cipher that let you search the field partly and also let you sort with the field.
- IvCihper is a week cipher for integer field that let you sort with the field.
Releases
v0.1.0 2020-06-20
- First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-safe-fields-0.1.0.tar.gz
.
File metadata
- Download URL: django-safe-fields-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3d40ec009ca00be41c300e7bd117de664f576a480184b6febfe08c52cd7ab67 |
|
MD5 | 8c6aa23b1d16a1b0c46d7a3cee4fbbba |
|
BLAKE2b-256 | 55d64418428f4afe3db3db4b4d0407ccd02b5a9a9ef3c631d5ac21c32b0208de |