All Projects → luojilab → django-mirage-field

luojilab / django-mirage-field

Licence: MIT license
Django model field encrypt/decrypt your data, keep secret in database.

Programming Languages

python
139335 projects - #7 most used programming language
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to django-mirage-field

AES
AES for microcontrollers (Arduino & Raspberry pi)
Stars: ✭ 116 (+34.88%)
Mutual labels:  aes, cipher, cbc
Netcore.encrypt
NETCore encrypt and decrpty tool,Include aes,des,rsa,md5,sha1,sha256,sha384,sha512
Stars: ✭ 339 (+294.19%)
Mutual labels:  aes, encrypt
Python-File-Encryptor
Encrypt and Decrypt files using Python (AES CBC MODE)
Stars: ✭ 51 (-40.7%)
Mutual labels:  aes, cbc
Swcrypt
RSA public/private key generation, RSA, AES encryption/decryption, RSA sign/verify in Swift with CommonCrypto in iOS and OS X
Stars: ✭ 632 (+634.88%)
Mutual labels:  aes, encrypt
crypthash-net
CryptHash.NET is a .NET multi-target library to encrypt/decrypt/hash/encode/decode strings and files, with an optional .NET Core multiplatform console utility.
Stars: ✭ 33 (-61.63%)
Mutual labels:  aes, cbc
dingtalk-encrypt
dingTalk encrypt Node Version. 钉钉的非官方nodejs版AES加解密库 sdk
Stars: ✭ 16 (-81.4%)
Mutual labels:  aes, encrypt
AES
C++ AES implementation
Stars: ✭ 365 (+324.42%)
Mutual labels:  aes, cipher
openssl
A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption.
Stars: ✭ 199 (+131.4%)
Mutual labels:  aes, cbc
Cryptoswift
CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift
Stars: ✭ 8,846 (+10186.05%)
Mutual labels:  aes, cipher
Hybrid Crypto Js
RSA+AES hybrid encryption implementation for JavaScript. Works with Node.js, React Native and modern browsers.
Stars: ✭ 87 (+1.16%)
Mutual labels:  aes, encrypt
Encrypt Body Spring Boot Starter
(停止维护,替代品搜索:https://github.com/search?l=Java&q=encrypt&type=Repositories )SpringBoot控制器统一的响应体加密与请求体解密的注解处理方式,支持MD5/SHA/AES/DES/RSA
Stars: ✭ 198 (+130.23%)
Mutual labels:  aes, encrypt
common-secure
提供一些加密算法java代码封装 包括 RSA/AES/DES/3DES/MD5/SHA/HmacSHA256
Stars: ✭ 37 (-56.98%)
Mutual labels:  aes, encrypt
jscrypto
Crypto library for Node/ES6/Typescript/Browser.
Stars: ✭ 20 (-76.74%)
Mutual labels:  aes, cipher
WebCrypto.swift
A small collection of cryptographic functions based on the JavaScript WebCrypto API.
Stars: ✭ 16 (-81.4%)
Mutual labels:  aes, cipher
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+176.74%)
Mutual labels:  aes, encrypt
Forge
A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
Stars: ✭ 4,204 (+4788.37%)
Mutual labels:  aes, cipher
crypto
🔐 Fastest crypto library for Deno written in pure Typescript. AES, Blowfish, CAST5, DES, 3DES, HMAC, HKDF, PBKDF2
Stars: ✭ 40 (-53.49%)
Mutual labels:  aes, cbc
Siv Mode
RFC 5297 SIV mode of operation in Java
Stars: ✭ 22 (-74.42%)
Mutual labels:  aes, cipher
Encrypt
🔒 A set of high-level APIs over PointyCastle for two-way cryptography.
Stars: ✭ 199 (+131.4%)
Mutual labels:  aes, cipher
CppSecurity
C++ Security Library
Stars: ✭ 24 (-72.09%)
Mutual labels:  aes, cipher

django-mirage-field

Hits

NOTE!!!

The maintainer tcitry has resigned from luojilab, he won't contribute this project ever, the latest code please refer: tcitry/django-mirage-field.

Introduce

A Django model fields collection that encrypt your data when save to and decrypt when get from database. It keeps data always encrypted in database. Base on AES, it supports query method like get() and filter() in Django.

Mirage can also migrate data from origin column to encrypted column in database with a good performance.

Features

  • Use settings.SECRET_KEY as secret key default or anyelse which length >= 32
  • Support CharField, TextField, IntegerField, EmailField
  • Support Django ORM's get(), filter() query method
  • Support AES-256-ECB and AES-256-CBC(v1.2.0)
  • Support PostgreSQL and MySQL database
  • Support Django model field db_index and unique attributes

Installation

pip install django-mirage-field

Usage

from mirage import fields
class TestModel(models.Model):
    age = fields.EncryptedIntegerField()
obj = TestModel.objects.get(age=18)
obj.id          # 1
obj.age         # 18
type(obj.age)   # int
database=# select * from testmodel where id = 1;
         id          |           age
---------------------+--------------------------
 1 | -bYijegsEDrmS1s7ilnspA==
from mirage.crypto import Crypto
c = Crypto()                      # key is optional, default will use settings.SECRET_KEY
c.encrypt('some_address')               # -bYijegsEDrmS1s7ilnspA==
c.decrypt('-bYijegsEDrmS1s7ilnspA==')   # some_address

Settings

  • MIRAGE_SECRET_KEY
  • MIRAGE_CIPHER_MODE (v1.2.0+)
  • MIRAGE_CIPHER_IV (v1.2.0+)

MIRAGE_SECRET_KEY

You can use the settings.SECRET_KEY as default key, if you want custom another key for mirage, set the MIRAGE_SECRET_KEY in settings.

Mirage will get the settings.MIRAGE_SECRET_KEY first, if not set, mirage will get the settings.SECRET_KEY.

MIRAGE_CIPHER_MODE

MIRAGE_CIPHER_MODE is optional, choices are below, If don't set, default is ECB.

  • ECB
  • CBC

MIRAGE_CIPHER_IV

MIRAGE_CIPHER_IV is optional, if you don't set, it will use a default: "1234567890abcdef", it's length must be 16.

Model Fields

  1. EncryptedTextField
  2. EncryptedCharField
  3. EncryptedEmailField
  4. EncryptedIntegerField
  5. EncryptedURLField(v1.3.0+)

Data Migrate

AddmiragetoINSTALLED_APPS

Way 1. Migrations

add app_name,model_name,field_name in migrations.RunPython

from mirage.tools import Migrator

migrations.RunPython(Migrator("app_name", "model_name", "field_name").encrypt, reverse_code=Migrator("app_name", 'model_name', 'field_name').decrypt),

Way 2. Commands

Options:

  • --app
  • --model
  • --field
  • --method (optional: encrypt, decrypt, encrypt_to, decrypt_to, copy_to)
  • --tofield (need when use encryt_to, decrypt_to, copy_to method)

Optional options:

  • --offset ("select * from xxx where id > offset")
  • --total ("select * from xxx order by id limit total")
  • --limit: set the query count in every update, default is 1000, if you set -1, mirage will query all rows one time to update.

Examples

./manage.py mirage --app=yourapp --model=testmodel --field=address --method=encrypt --offset=2000000 --total=3000000

./manage.py mirage --app=yourapp --model=testmodel --field=address --method=encrypt_to --tofield=encrypted_address

Exceptions

from mirage import exceptions
  1. EncryptedFieldException

Performance

With ECB mode

Migrate data: 6000,000 columns takes 40 minutes, Average 1 column/2.5ms

Only encrypt/decrypt: Average 1 value/ms

Clients

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].