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 6567859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:12+00:00 2026-05-25T14:23:12+00:00

I am new to encryption. I need to keep a field encrypted in a

  • 0

I am new to encryption. I need to keep a field encrypted in a table (DocNumber). I keep this as an encrypted varbinary field by setting:

   docNumber = ENCRYPTBYPASSPHRASE('password', @docnumber)

When I want to query the table using docnumber I do the following:

   WHERE docNumber = DECRYPTBYPASSPHRASE('password', @docNumber)

However it fails to return eligible records. Then I observed that if I call ENCRYPTBYPASSPHRASE() repeatedly with same password and value, I end up getting different encrypted values.
Where am I making the mistake? How do you normally tackle this?

  • 1 1 Answer
  • 0 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-25T14:23:13+00:00Added an answer on May 25, 2026 at 2:23 pm

    I’ve always used it this way, just a slightly different way to organize the predicate:

    WHERE CONVERT(VARCHAR(64), DECRYPTBYPASSPHRASE('password', docNumber)) = @docNumber;
    

    The difference is that you are running the decrypt on the original value, which includes the cipher at save time, whereas in the version you were trying, you are decrypting again and this generates a different cipher.

    EDIT adding a sample using HASHBYTES():

    USE tempdb;
    GO
    CREATE TABLE dbo.enctest(x VARBINARY(64));
    GO
    INSERT dbo.enctest(x) SELECT HASHBYTES('SHA1', 'foo');
    INSERT dbo.enctest(x) SELECT HASHBYTES('SHA1', 'bar');
    GO
    SELECT x FROM dbo.enctest WHERE x = HASHBYTES('SHA1', 'foo');
    GO
    DROP TABLE dbo.enctest;
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store sensitive information (a symmetric encryption key that I want to
I am totally new to encryption, so this question might be trivial - however,
So I'm working on an application where I need to decrypt encrypted files.The encryption
I'm new to encryption. I need to implement asymmetric encryption algorithm, which i think
New to javascript/jquery and having a hard time with using this or $(this) to
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
I want to design a new distributed application, but I have a few queries
I need to perform a 128-bit RC4 encryption, I'm using .NET and C#. Is
I need to implement salts in my encryption, but to do so, I need
I have a char* string that I have encoded using AES encryption. This string

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.