0

I'm building an application in which the database records are encrypted. All the user can see is "content" and "line":

enter image description here

The user can see the line # but the content is encrypted.

While I like the security this offers, it makes it extremely hard to search. If I want to search the records for a specific sub-string, I have to pull all records and decrypt each one one-by-one checking for matches (and I want to return all records that match, so I can't just stop at the first match).

It's especially problematic in my case because I'm using Firebase's free tier which only allows 5000 reads (that's 5000 records) a day. My entire data set is just over 3000 records, so after 1 search, I'm done for the day.

Encrypting database records is a common thing, and so is searching database records for matching sub-strings, so I can't imagine I'm the first to run into this problem. So my question is: how is this problem usually solved?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
gib65
  • 1,709
  • 3
  • 24
  • 58
  • Maybe this [resource](https://medium.com/firebase-tips-tricks/how-to-filter-firestore-data-cheaper-705f5efec444) will help. – Alex Mamo Mar 29 '23 at 07:19

1 Answers1

1

To allow searching the encrypted data, you'll need to encrypt the search term in the same way that you encrypted the data. If you do that correctly, you'll end up with a search term of "bHbUwMVV72R... and can then use that to match the string in your database.

But Firestore can't search for a substring, so even with this encrypted search term you can only do full (==) and prefix (>= and <=) matches. For more on this see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807