georgemarshall / django-cryptography

Easily encrypt data in Django
https://django-cryptography.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
371 stars 70 forks source link

SQL query to decrypt field #48

Closed daniel12564 closed 3 years ago

daniel12564 commented 3 years ago

Hi, I'm generating some reports with data obtained via SQL queries but now some of this fields are encrypted because of client request. I would like to know if it's possible to build a query to obtain the decrypted value of an encrypted field. Thanks

georgemarshall commented 3 years ago

While it is possible to extend SQL databases with custom function calls capable of decoding the encrypted bytes. You would be fighting an uphill battle of re-implementing the key derivation function (KDF) and decryption functions as something that can be accessed via a SQL query.

As such this request goes beyond the scope of this project. The intention of this Django Module is to restrict access of the data to the application layer only, hence why it is stored as encrypted bytes in the database.