查询列出数据库的加密证书


15

使用什么证书来加密实例上的每个数据库。

我可以使用以下方法获取数据,但是如何编写查询

USE master
GO

-- this provides the list of certificates
SELECT * FROM sys.certificates


-- this provides the list of databases (encryption_state = 3) is encrypted
SELECT * FROM sys.dm_database_encryption_keys
 WHERE encryption_state = 3;

我注意到sys.certifcates.thumbprint和sys.dm_database_encryption_keys.encryptor_thumbprint列包含相同的数据。

Answers:


19

您可以加入证书指纹:

use master;
go

select
    database_name = d.name,
    dek.encryptor_type,
    cert_name = c.name
from sys.dm_database_encryption_keys dek
left join sys.certificates c
on dek.encryptor_thumbprint = c.thumbprint
inner join sys.databases d
on dek.database_id = d.database_id;

我的示例输出:

database_name           encryptor_type    cert_name
=============           ==============    =========
tempdb                  ASYMMETRIC KEY    NULL
AdventureWorks2012TDE   CERTIFICATE       TdeCert

请注意,该encryptor_type字段仅在SQL 2012+上可用。
LowlyDBA

1

对于更深入的查询(显示哪些数据库已加密),请提供其证书,以及是否真正完成加密设置的重要提示。加密有时可能需要很长时间才能完成或卡住。

SELECT D.name AS 'Database Name'
,c.name AS 'Cert Name'
,E.encryptor_type AS 'Type'
,case
    when E.encryption_state = 3 then 'Encrypted'
    when E.encryption_state = 2 then 'In Progress'
    else 'Not Encrypted'
end as state,
E.encryption_state, E.percent_complete, E.key_algorithm, E.key_length, E.* FROM sys.dm_database_encryption_keys E
right join sys.databases D on D.database_id = E.database_id
left join sys.certificates c ON E.encryptor_thumbprint=c.thumbprint
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.