Skip to main content

Django Sage Encrypt

django-sage-encrypt is a package based on Django Web Framework & PostgreSQL for database at rest encryption.

Project Detail

You can find all technologies we used in our project into these files: * Version: 1.0.0 * Frameworks: - Django 3.2.4 * Database: - PostgreSQL 10 * Language: Python 3.9.4

Installation

First install package

$ pip install django-sage-encrypt

Then add ‘sage_encrypt’ to INSTALLED_APPS in settings.py

INSTALLED_APPS = [
  ...
  'sage_encrypt',
  ...
]

Also you need to install pgcrypto extension in your database:

sudo -u postgres psql <db_name>
CREATE EXTENSION pgcrypto;

Fields

For encrypting each row of your database there are multiple ways:

  1. use encrypt_field function in your models.py

from django.db import models
from sage_encrypt.services.encrypt import encrypt_field

# symmetric encryption
title = encrypt_field(models.CharField(max_length=255))

# asymmetric encryption
title = encrypt_field(models.CharField(max_length=255), algorithm='asymmetric')
  1. use field directly

# symmetric encryption
from sage_encrypt.fields.symmetric import EncryptedCharField

title = EncryptedCharField(max_length=255)


# asymmetric encryption
from sage_encrypt.fields.asymmetric import EncryptedCharField

title = EncryptedCharField(max_length=255)

If you want to use symmetric encryption you don’t need to generate secret keys default is SECRET_KEY

But if you want to use asymmetric encryption you have to generate private key & public key

Generate secret key

# generate private & public key
gpg --gen-key # in password section do not enter password

gpg --list-keys
# output
pub   rsa3072 2021-06-20 [SC] [expires: 2023-06-20]
      <test_token_generated>
uid           [ultimate] Test <test@gmail.com>
sub   rsa3072 2021-06-20 [E] [expires: 2023-06-20]

gpg -a --export <test_token_generated> > public.key
gpg -a --export-secret-keys <test_token_generated> > private.key

Settings

Here are the parameters that you can set from setting:

Parameter

Description

ENCRYPT_KEY

Secret key that using for symmetric encryption. default: SECRET_KEY

ENCRYPT_PRIVATE_KEY

Private key for asymmetric encryption. default: None

ENCRYPT_PUBLIC_KEY

Private key for asymmetric encryption. default: None

Management Commands

sage_encrypt provides 2 management commands:

  1. encryptdb

python manage.py encryptdb --table <table_name> --column <col_name> --cast <field_previous_cast_type> --algorithm <algorithm> #(symmetric/asymmetric)

Options:

  1. –database (if you have multiple db’s specify for your database)

  2. –table (table name in your database not django model title)

  3. –column (col name in the specified table)

  4. –algorithm (symmetric/asymmetric)

  5. –cast (field previous cast that you want to encrypt from that)

Usage:

When you want to add encryption on a row and there is valuable data in you db, you can encrypt the data to be compatible with Encrypted Field.

  1. decryptdb

python manage.py decryptdb --table <table_name> --column <col_name>

Options:

  1. –database (if you have multiple db’s specify for your database)

  2. –table (table name in your database not django model title)

  3. –column (col name in the specified table)

Usage:

When your data is encrypted in db and you want to remove encryption from a row, for getting back data you can use this command, it decrypts data and replaces in your db.

Metadata

Release files for django-sage-encrypt 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-sage-encrypt 0.4.4
File Size Uploaded Provenance
django-sage-encrypt-0.4.4.tar.gz 21.6 kB Without provenance Details

Release files / django-sage-encrypt-0.4.4.tar.gz

Download URL django-sage-encrypt-0.4.4.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
06faa647be2f8c916d84d1a71287e5a1c535b4d066467b9ae0154f3e5b9afd65
BLAKE2b-256 checksum
How to use checksums
c58b1277067b7fcfdc286327c6dc845126735af6de665d58dcfbf724ca1fc4b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Security for django-sage-encrypt 0.4.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page