I am trying to implement the Always-Encrypted feature on a few columns of an MS SQL Server 2016 DB. I have, in fact, successfully implemented it on my UAT DB. However, when trying to do the identical steps on my production DB, I am getting the following error:
Set-SqlColumnEncryption : 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: 'xx-xx-xx-xx-xx-xx-xx-xx-xx-xx'. Keyset does not exist
Some details: I am executing the command
Set-SqlColumnEncryption -ColumnEncryptionSettings $l_columnEncryptionSettings -InputObject $l_database
within powershell. The master column key IS in the ms sql user store of the account running the process. It can be seen in certmgr in "Certificates - Current User\Personal\Certificates", and it contains both the public and private key (displaying the cert info shows "you have a private key that corresponds to this certificate").
Looking at the Always-Encrypted Keys
entries in the DB, the Column Master Key
shows with a keypath of CurrentUser/my/<fingerprint>
, where the <fingerprint>
does indeed match the fingerprint of the certificate in the MSSQL_CERTIFICATE_STORE.
I have seen this question (Always Encrypted Feature - Failed to decrypt column. Call from Windows-Service App), but the "solution" there either does not apply (I have imported public and private key into store), or is unclear (it mentions "access" to a directory, but details of what kind of access are not provided, and the account I am dealing with does indeed have read access to the directory mentioned.)
What is most strange is that I have already successfully implemented it on the same machine for the UAT DB (different DB, same SQL instance, different user), but I can see no differences between the two setups.
Does anyone know what might be causing this error or how to correct it? Thanks.
Edit: When I posed this question, the problem appeared to be with some incorrect setup for the feature, so the question was reasonable. On further investigation (see below), it turned out to be data corruption, so no one but myself could possibly have answered this.