Always Encypted Certificates

David Chase 681 Reputation points
2020-10-21T20:35:29.577+00:00

I just setup Always Encrypted on our SQL Server 2016 Std server on a test database. The master key and encryption key were created as CMK_Auto1 and CEK_Auto1. I chose "Windows certificate store" and "Master key source" of Current User. I searched for where they are stored and I found HKEY_CURRENT_USER in the registry but I cannot find anything there.

Also, when we encrypt the production server how can I restore the production database to my development database without having those certificates on my development database?

SQL Server | Other
{count} votes

Accepted answer
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2020-10-22T21:13:12.927+00:00

    Also, when we encrypt the production server how can I restore the production database to my development database without having those certificates on my development database?

    I meant to answer this question last night, but something must have happened. It seems that Amelia has answered the first half of your post, but I don't think her answer to your second question is what you are looking for.

    There is no problem with copying the production database elsewhere. In difference to TDE there are no keys you need to worry about. As long as you are connecting from a client that has all the certificates you can retrieve the data. Keep in mind that all decryption/encryption occurs client-side. Thus, if you move to a new client machine, for instance a new laptop, you need to copy the certificates and you need to store them in the same place. (The location for the certificates are stored in the database.)

    Amelia suggests that you should first remove the encryption before you copy the database. I think you agree that this is a terrible idea.


2 additional answers

Sort by: Most helpful
  1. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2020-10-22T06:21:11.797+00:00

    Hi @David Chase ,
    If you chose Certificate Store - Current User as key store, then the certificate is stored in %APPDATA%\Roaming\Microsoft\SystemCertificates\My\Certificates.
    34232-1.jpg

    You also can find it in certmgr.msc->Personal->Certificates.
    34233-2.jpg

    -how can I restore the production database to my development database without having those certificates on my development database?

    You can go to database-> Tasks-> Encrypt Columns to open the Always Encrypted Wizard.
    On the Column Selection page, set the Encryption Type to Plaintext to remove always encrypted from a column.
    34207-3.jpg

    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2020-10-23T08:10:01.367+00:00

    Hi @David Chase ,
    Thanks for your reply.
    When you back up a database, the resulting backup file contains encrypted stored in encrypted columns and all metadata for Always Encrypted keys. When you restore a database, all encrypted data and all metadata for Always Encrypted keys are restored. You just need to export and import Always encrypted certificate from development server to development server. Please refer to Exporting and Importing SQL Server Always Encrypted Certificates for more details.
    Based on my test, after importing the certificate, the Always encrypted will work fine in the target server.
    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

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.