I need a way to store encrypted data, in a way that I can still run queries. Is that even possible?
At least I need an encryption algorythm that always returns the same string for the same input, so I can find all the users named ‘John’ by encrypting that string and looking for the encrypted result in the DB. In PHP, mcrypt always returns different strings (I know this is on purpose, to improve security).
Any ideas?
Depends on how you’re storing that ‘John’ name. If it’s the ONLY thing in a particular field, you can do something like
If ‘John’ is part of a larger string (‘John Doe’ or ‘King John, Ruler of the Universe’), then you’ll have to decrypt the full field and match against that
Note that I’m embedding the decryption key in the query. Bad idea for a production system, but this is just an example.
You won’t be able to do something like:
due to how AES and most other userful/decent crypto systems work.