﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34246	Feature: Add new type of fields - cryptofields	Nikolay Fedorov	nobody	"**Idea**
Add new type of fields - cryptofields which store data in the database in encrypted form (bytes) and crypt and decrypt data on the fly.
As example with Fernet (symmetric encryption).
{{{
from django.db import models
from cryptography.fernet import Fernet

CRYPTO_KEY = b'99lectrHf-urwE8CEXAqCf2UofCb-K-rEiT_VdRWhXY='

class CryptoCharField(models.CharField):

    description = _(""Crypto char field"")

    def value_from_object(self, obj):
        val = getattr(obj, self.attname)
        if val not in (None, """", b""""):
            val = settings.CYPHER.decrypt(val).decode('utf-8')
        return val

    def get_internal_type(self):
        return ""BinaryField""

    def get_db_prep_value(self, value, connection, prepared=False):
        value = super().get_db_prep_value(value, connection, prepared)
        if value is not None:
            return connection.Database.Binary(Fernet(CRYPTO_KEY).encrypt(value.encode('utf-8')))
        return value
}}}
"	New feature	closed	Database layer (models, ORM)	4.1	Normal	wontfix			Unreviewed	0	0	0	0	0	0
