Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1036505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:42:58+00:00 2026-05-16T14:42:58+00:00

I am looking to apply SQL column level encryption using symmetric keys. The initial

  • 0

I am looking to apply SQL column level encryption using symmetric keys. The initial steps needed to create the Database Master Key, Certificates and Symmetric Keys seems straight forward and I have tested encrypting/decrypting data using Symmetric Keys successfully.

However, once the data is encrypted I don’t know how best to query it. E.g.

SELECT PlainTextA, PlainTextB, PlainTextC 
WHERE CONVERT(varchar, DECRYPTBYKEY(EncyptedColumn)) = @SearchTerm

would surely result in a full table scan?

Another option I thought might work is encrypting the search criteria first e.g.

SELECT PlainTextA, PlainTextB, PlainTextC 
WHERE EncyptedColumn = ENCRYPTBYKEY(KEY_GUID('KeyName'), @SearchTerm)

but this doesn’t work as the encrypted value generated is always different.

Any suggestions would be greatly appreciated.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:42:59+00:00Added an answer on May 16, 2026 at 2:42 pm

    The typical way is to store both the encrypted value and a one-way hash of the value. When you seek a specific value, you would seek the hash. This way you can query efficiently, w/o having to decrypt every row in order to find the value you’re interested:

    create table Table (
    EncryptedColumn varbinary(max),
    HashValue binary(20),
    PlainA int,
    PlainB varchar(256),
    PlainC Datetime);
    
    create index ndxTableHash on Table(HashValue);
    
    select PlainA, plainB, PlainC
    from table
    where HashValue = HashBytes('SHA1', @searchTerm);
    

    In theory, you can have a hash conflict once in a blue moon, to be paranoid-safe you add a double check on the decrypted column:

    select PlainA, plainB, PlainC
    from table
    where HashValue = HashBytes('SHA1', @searchTerm)
    and DecryptByKey(..., EncryptedColumn) = @searchTerm;
    

    Also see Indexing encrypted data and SQL Server 2005: searching encrypted data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started looking into encryption using keys and certificates in sql server 2005/08 and
I'm looking for a way possibly using VBA to apply a cell's fill value
I'm looking for a multi-column database, but even SQLite at over a megabyte seems
I'm looking for a concise and functional style way to apply a function to
I'm looking for something similar to this: Active navigation with jQuery - can't apply
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking at the Slickgrid examples and using Google Chrome, I'm setting a breakpoint on
I am looking for T-SQL code to list all tables in all databases in
I've been looking at the following post and trying to apply it to mine
I'm looking how to replace/encode text using RegEx based on RegEx settings/params below: RegEx.IgnoreCase

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.