无法通过证书将对称密钥作为SQL用户帐户打开

时间:2011-11-29 17:53:37

标签: sql-server-2008 encryption certificate

我使用这样的证书创建我的密钥:

CREATE SYMMETRIC KEY some_Key_01
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE myCert;
GO

GRANT VIEW DEFINITION ON CERTIFICATE::myCert TO sqlUser;
GO

GRANT VIEW DEFINITION ON SYMMETRIC KEY::some_Key_01 TO sqlUser;
GO

然后我试着打开它,就像这样:

OPEN SYMMETRIC KEY some_Key_01
DECRYPTION BY CERTIFICATE myCert;
GO
SELECT CONVERT(datetime, DecryptByKey(EncryptedField))
AS 'DecryptedField'
FROM MyTable;
GO

但我收到的消息:
Msg 15151, Level 16, State 1, Line 23
Cannot find the certificate 'myCert', because it does not exist or you do not have permission.

1 个答案:

答案 0 :(得分:6)

您需要获得证书的control权限:

GRANT CONTROL ON CERTIFICATE::myCert TO sqlUser;
GO

并授予关键密钥references权限:

GRANT REFERENCES ON SYMMETRIC KEY::some_Key_01 TO sqlUser;
GO