I create my key using a certificate like this:
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
Then I try to open and us it like this:
OPEN SYMMETRIC KEY some_Key_01
DECRYPTION BY CERTIFICATE myCert;
GO
SELECT CONVERT(datetime, DecryptByKey(EncryptedField))
AS 'DecryptedField'
FROM MyTable;
GO
But I get the message:
Msg 15151, Level 16, State 1, Line 23
Cannot find the certificate 'myCert', because it does not exist or you do not have permission.
You need to have the
controlpermission on the certificate:And grant
referencespermission on the key: