Optimal datatype for storing encrypted field data
I have a sql databse which is required to store a set of demographic personal data which must be queried quickly.
Requirements dictate the data must be encrypted as it is personal information but also must be searched on to allow record matching.
My question is what datatypes should I define these fields as which will store e开发者_运维技巧ncrypted data should they be a varchar or varbinary?
My thinking is a that varbinary will reduce the unnecessary overhead in the code to convert the encrypted data to a base64 string, however will querying this data in sql be a lot slower than querying varchar fields. I am not sure how varbinary fields perform with non clustered indexes?
[edit] My question is really aimed at query performance. Will storing varbinary data affect query performance when comparing fields for equality?
What I have done in the past is compute a hash of the data that is encrypted and store that in another column. The hash can be a varchar field which you could index. Overall I think the varchar field would allow for better query performance compared to a varbinary search.
You need to secure that database as a whole - not individual fields. Otherwise you won't be able to query them.
精彩评论