47ng/prisma-field-encryption

Filter with "contains"

Closed this issue · 1 comments

Hello, thank you for an amazing library. How can I enable "contains" filtering, if it's possible?

As stated in the filtering documentation (emphasis added):

This is because the encryption is not deterministic: encrypting the same input multiple times will yield different outputs, due to the use of random initialisation vectors to keep ciphertext safe. Therefore Prisma cannot match the query to the data.

To circumvent this issue, the extension provides support for a separate field containing a hash of the clear-text input, which is stable and can be used for exact matching (partial matching like startsWith, contains is not possible).

It would technically be possible to use something like homomorphic encryption to enable arbitrary search on encrypted fields, but since current implementations would take several minutes to return results, I doubt it's something worth exploring further for this use-case until more performant solutions show up.

Read more here: https://soatok.blog/2023/03/01/database-cryptography-fur-the-rest-of-us/