I have a database which stores some fields as encrypted data. The reason for this is because if the database is accessed from the server then server staff cannot get a list of names and email addresses.

But the problem is that when I retrieve a list of my users from my control panel, I cannot sort them ASC or DESC on the fields that have been encrypted. Of course the data can be decrypted and displayed normally for me to read, but how to sort those columns when they are stored like...

0605040977504E5C504A5F555259415A5D515A5F565
555259415A5D515A5F565D413E2A14CAD06D
D06D901720C7FDB7BD596BA429B4CE3CDA08B4CE
504E5C504A5F555259415A5D515A5F565D413E2A1

We eventually solved this one by creating an extra column for an index using the first few letters of the subject line, so the column sorted looks like...

ADAYATTHE
AMIDSUMME
HOWTOADDA
THEFIRSTO
WHATAJOKE

This way the records could be sorted in alphabetical order, and yes it can have some duplicates but at least they will be listed in the correct order of things and should one be investigated or hacked then they won't be getting any easy clues as to what is what.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.