diff --git a/oidc4vp/migrations/0002_organization_encrypted_sensitive_data_and_more.py b/oidc4vp/migrations/0002_organization_encrypted_sensitive_data_and_more.py new file mode 100644 index 0000000..5108fc3 --- /dev/null +++ b/oidc4vp/migrations/0002_organization_encrypted_sensitive_data_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.5 on 2024-02-23 13:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('oidc4vp', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='encrypted_sensitive_data', + field=models.CharField(default=None, max_length=255, null=True), + ), + migrations.AddField( + model_name='organization', + name='salt', + field=models.CharField(default=None, max_length=255, null=True), + ), + ] diff --git a/oidc4vp/models.py b/oidc4vp/models.py index b0d8b26..b616c11 100644 --- a/oidc4vp/models.py +++ b/oidc4vp/models.py @@ -149,24 +149,24 @@ class Organization(models.Model): self.encrypted_sensitive_data = key_crypted def encrypt_data(self, data): - pw = self.decrypt_sensitive_data() + pw = self.decrypt_sensitive_data().encode('utf-8') sb = self.get_secret_box(pw) value_enc = sb.encrypt(data.encode('utf-8')) return base64.b64encode(value_enc).decode('utf-8') def decrypt_data(self, data): - pw = self.decrypt_sensitive_data() + pw = self.decrypt_sensitive_data().encode('utf-8') sb = self.get_secret_box(pw) value = base64.b64decode(data.encode('utf-8')) return sb.decrypt(value).decode('utf-8') def get_secret_box(self, password): - sb_key = self.derive_key_from_password(password) + sb_key = self.derive_key_from_password(password=password) return secret.SecretBox(sb_key) def change_password_key(self, new_password): data = self.decrypt_sensitive_data() - sb_key = self.derive_key_from_password(new_password) + sb_key = self.derive_key_from_password(password=new_password) sb = secret.SecretBox(sb_key) if not isinstance(data, bytes): data = data.encode('utf-8')