Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a query over encrypted field #17

Closed
nairdaus opened this issue Mar 31, 2016 · 2 comments
Closed

Make a query over encrypted field #17

nairdaus opened this issue Mar 31, 2016 · 2 comments

Comments

@nairdaus
Copy link

Hello, I'm using your library django encrypted fields and I have a problem when I make a query on the encrypted field. I'm using myModel.objects.filter(names__istartswith = mysearch) and django shows me the result decrypted, but the search is done over the encrypted text, for example: I search names with "A" and it shows me: Roberto... because its encrypted value is AB59cOgUT1lf.............. on my database.

Is there any command I can use to solve this issue? or any way you can suggest me so I can decrypt the field before doing the search?

@defrex
Copy link
Owner

defrex commented Mar 31, 2016

Unfortunately what you're asking for is impossible. The decryption is done in the application layer, and the query is running in the DB layer.

Django simply turns MyModel.objects.filter(names__startswith='mysearch') into a SQL query roughly like SELECT * from myapp_mymodel where names LIKE 'mysearch%';.

You either have to live without querying, or store the data unencrypted.

@defrex defrex closed this as completed Mar 31, 2016
@rriehle
Copy link

rriehle commented Mar 31, 2016

As @defrex has said, once data is encrypted what you're asking of the database is impossible. A work around is to load required fields into data structures at the application layer and then to run queries across those data structures. At that point "running queries" involves Python, not SQL or the Django ORM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants