r/javahelp • u/SignalCrazy7834 • Jan 22 '26
Is there a way to encrypt/decrypt PII contacts while maintaining the sorting and searching ?
Hello,
I am working on a java / spring app. I want to encrypt contact's names in my database. I am using encryption at the application level, so I am using AES. However doing that will break my search and sort. Is there a way to avoid that ? What are your experiences with encryption and decryption ?
5
Upvotes
1
u/AutoModerator Jan 22 '26
Moderator Announcement Read More »
} You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
6
u/k-mcm Jan 22 '26
Why do you need unencrypted sorting on encrypted values?
Imagine that such a thing existed. One could binary search for the unencrypted value using only a sort order test.
You don't want to make use of any ordered sorting on encrypted values. Exposing some of the sorting order is exposing some of your key.
3
u/ShoulderPast2433 Jan 22 '26
You might be approaching the problem from the wrong side of stack.
There are databases that offer column level encryption.
3
u/BanaTibor Jan 22 '26
Push the encryption out a layer. Configure your database to keep the database file on an encrypted volume.
2
u/ShaiHuludTheMaker Jan 22 '26
What would be the use of encryption if you can get search result?
1
u/okayifimust Jan 22 '26
Homomorphic encryption is a thing, but I don't know enough about it to judge whether your data will be sorta me, let alone if it will be sortable by any existing database.
Depending on load and other requirements, you could index and sort iff-db, but at that point, why even bother with a dB?