Re: Search encrypted column in SQL 2005http://msdn.microsoft.com/wn3/a



Brian (Brian@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
Can someone provide me a sample of how to search encrypted column? Using
below method seems pretty slow.

select FirstName, LastName,
convert(varchar,decryptbykey(SSN)) as SSN
from PatientTable
WHERE convert(varchar,decryptbykey(SSN)) = '123-45-6789'

Yes, if you encrypt key columns it will be very very slow. There is no
way an index can be used, and the decryption is expensive too.

Take a look at the HashBytes() function. This gives a deterministic
hash of the key value, which is good for quick key lookups. It's of
course less good for security, since an intruder who is looking for a
person with a known SSN easily will find what he is looking for. But
security and performance don't go hand in hand.

The alternative is to use application-specific keys like customer numbers.
Then you can encrypt the SSN fully. But this also means that if the
customer calls in, and don't know his customer number, but only the SSN,
the helpdesk will not be able to find his data.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Search encrypted column in SQL 2005http://msdn.microsoft.com/w
    ... convert(varchar,decryptbykey(SSN)) as SSN ... if you encrypt key columns it will be very very slow. ... The alternative is to use application-specific keys like customer ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.sqlserver.security)
  • Re: Opinions on approach, please...
    ... Having a customer row shouldn't stop ... SSN CHARNOT NULL ... AS ROW CHANGE TIMESTAMP ... I accidentally forgot to show ROWID as the row finder. ...
    (comp.lang.cobol)
  • Re: Adding a UNIQUE constraint
    ... Columnist, SQL Server Professional ... I think you forgot 'WHERE SSN IS NOT NULL' in the view definition? ... > You are allowed only one null in a unique constraint. ... > SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • VBA: Pull Record Into UserForm
    ... I have a worksheet full of Customer Information. ... I want to pull the customers LName, FName, SSN, and info into my form ... Dim LName As String ...
    (microsoft.public.excel.programming)
  • Re: Search encrypted column in SQL 2005http://msdn.microsoft.com/w
    ... We are required to encrypt SSN and customer credit card number. ... The alternative is to use application-specific keys like customer numbers. ...
    (microsoft.public.sqlserver.security)