on-internet
← Community

Django Custom Field with Fernet Cannot Decrypt

Stack Overflow ·

This is my custom field that I call in a model. Migrations succeed and I'm able to insert an encrypted value into the data table. However, it will not decrypt. Here's the custom field class: class SecureString(CharField): """Custom Encrypted Field""" #kdf = X963KDF(algorithm=hashes.SHA256(), # length=32, #sharedinfo=None, # backend=default_backend()) key = bytes(settings.FERNET_KEY,'utf-8') f = Fernet(key) def from_db_value(self, value, expression, connection): return self.f.decrypt(str.encode(value)) def get_prep_value(self, value): return self.f.encrypt(bytes(value, 'utf-8')) And here is the

Comments

Sign in or sign up to comment and upvote.

No comments yet.