mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Stockage en BDD des identifiants comnpay.
This commit is contained in:
parent
208d703d95
commit
d6fbabe341
1 changed files with 4 additions and 9 deletions
|
@ -27,7 +27,6 @@ def encrypt(key, s):
|
||||||
def decrypt(key, s):
|
def decrypt(key, s):
|
||||||
obj = AES.new(key)
|
obj = AES.new(key)
|
||||||
ss = obj.decrypt(s)
|
ss = obj.decrypt(s)
|
||||||
print(ss)
|
|
||||||
return ss.split(bytes(EOD, 'utf-8'))[0]
|
return ss.split(bytes(EOD, 'utf-8'))[0]
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +35,10 @@ class AESEncryptedField(models.CharField):
|
||||||
setattr(instance, self.name,
|
setattr(instance, self.name,
|
||||||
binascii.b2a_base64(encrypt(settings.AES_KEY, data)))
|
binascii.b2a_base64(encrypt(settings.AES_KEY, data)))
|
||||||
|
|
||||||
|
def value_from_object(self, obj):
|
||||||
|
return decrypt(settings.AES_KEY,
|
||||||
|
binascii.a2b_base64(getattr(obj, self.attname))).decode('utf-8')
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
|
@ -43,20 +46,12 @@ class AESEncryptedField(models.CharField):
|
||||||
binascii.a2b_base64(value)).decode('utf-8')
|
binascii.a2b_base64(value)).decode('utf-8')
|
||||||
|
|
||||||
def from_db_value(self, value, expression, connection, *args):
|
def from_db_value(self, value, expression, connection, *args):
|
||||||
print('from db')
|
|
||||||
print(value)
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
return decrypt(settings.AES_KEY,
|
return decrypt(settings.AES_KEY,
|
||||||
binascii.a2b_base64(value)).decode('utf-8')
|
binascii.a2b_base64(value)).decode('utf-8')
|
||||||
|
|
||||||
def get_prep_value(self, value):
|
def get_prep_value(self, value):
|
||||||
print('get prep value')
|
|
||||||
print(value)
|
|
||||||
print(binascii.b2a_base64(encrypt(
|
|
||||||
settings.AES_KEY,
|
|
||||||
value
|
|
||||||
)))
|
|
||||||
return binascii.b2a_base64(encrypt(
|
return binascii.b2a_base64(encrypt(
|
||||||
settings.AES_KEY,
|
settings.AES_KEY,
|
||||||
value
|
value
|
||||||
|
|
Loading…
Reference in a new issue