Decrypt error

David Chase 681 Reputation points
2020-10-21T22:56:50.597+00:00

I am testing Always Encrypted and I am getting the error below when my web page tries to read an encrypted column in a stored procedure. I ran the stored procedure from the server in SSMS and it worked fine. When I run the same stored procedure from my workstation SSMS connected to the same server I get the exact error below. What am I missing?

An unhandled exception occurred:
Message: Failed to decrypt column 'FirstName'.
Failed to decrypt a column encryption key using key store provider: 'MSSQL_CERTIFICATE_STORE'. The last 10 bytes of the encrypted column encryption key are: 'DD-73-EE-95-6F-75-A3-0A-63-84'.
Certificate with thumbprint '0F76519B0D08D52D6EBAF5BD2B86FA46E6DBAA7F' not found in certificate store 'My' in certificate location 'CurrentUser'. Verify the certificate path in the column master key definition in the database is correct, and the certificate has been imported correctly into the certificate location/store.
Parameter name: masterKeyPath
SQL Server Other
{count} votes

3 answers

Sort by: Most helpful
  1. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2020-10-22T03:02:10.8+00:00

    Hi @David Chase ,

    Please try below solution;

    1.Run (MMC)
    2.Select certificate in snap console.
    3.Locate your always encrypted certificate, either My user, or Machine Account
    4.Right click-> All tasks-> Manage private key.
    5.Add the windows user which is making SQL connection.
    6.User could the process user, it can be either IIS or any windows Logon user.

    Form this similar thread.

    Best regards,
    Cathy


    If the response is helpful, please click "Accept Answer" and upvote it.


  2. Ben Miller (DBAduck) 966 Reputation points
    2020-10-22T13:58:17.157+00:00

    Here is a pretty comprehensive setup of Always Encrypted. I think that the piece you are missing may be the certificate that needs to be put on the web server which completes the encryption. If you have the Column Master Key and the Column Encryption key and all these are good (your graphic is about those), then you need the certificate that is used to communicate with these keys.

    Take a look. configure-always-encrypted-sql-server-2016-using-ssms-powershell-t-sql


  3. David Chase 681 Reputation points
    2020-10-26T13:17:42.27+00:00

    One issue I found is that when I log into the server as the machine administrator I get the option for a machine master key source but not if I log in as the domain administrator.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.