我使用这样的证书创建我的密钥:
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.
答案 0 :(得分:6)
您需要获得证书的control
权限:
GRANT CONTROL ON CERTIFICATE::myCert TO sqlUser;
GO
并授予关键密钥references
权限:
GRANT REFERENCES ON SYMMETRIC KEY::some_Key_01 TO sqlUser;
GO