0

I have an IQueryable list of Customer entities (EntityFrameworks). I need to do an orderby on this IQueryable list but the issue is that the field that I want to use for ordering is encrypted in the database. Is there any way that I can decrypt this field prior to ordering? Can I write some kind of Linq extension for OrderBy. Since there could be thousands of Customers, I don't want to materialize the list just so it can be sorted...

1
  • 4
    Ew... I don't think you're gonna have fun with this... Oct 26, 2012 at 3:08

2 Answers 2

0

It does not seem to be possible right now.

It would be only possible in case the decryption take place in the database and as decryption algorithm can not be translated into SQL statement therefore it is not possible.

0

Because you've got an encrypted field there would be no possible way to order any list by the decryption value without first decryption every row. This is of course because to order you must know the values of the fields first, so unless there was some pattern in your encryption which would make for some ordering (in which case its a bad encryption algorithm!) then you're out of luck.

I would not suggest putting any decryption techniques within SQL as there would be no protection against somebody gaining access to the encrypted values if the database was compromised. For instance somebody gets hold of a backup of your database which contains all of the customer's encrypted values, along with the method to decrypt them!

A possible hacky solution would be to store some sort of ordering index, calculated from the encrypted value, in another column. Say for instance your data is alphabetic, you could store the first letter of the unencrypted value in another column, which would at least allow you to minimise the number of rows you need to bring over the line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.