You can view:
Copy codeThe Code is as follows:
About symmetric key encryption using certificate decryption
Create master key encryption by password = 'Password'
Go
Create certificate CertTest
With SUBJECT = 'test certificate'
GO
-- Create asymmetric keys
CREATE asypolicric KEY testasypolicric
With algorithm = RSA_2048
Encryption by password = 'password1 ';
GO
ALTER asypolicric KEY testasypolicric with private key (decryption by password = 'password1 ')
-- DROP asypolicric KEY testasypolicric
-- Create a symmetric key
CREATE foreign Ric KEY testforeign ric
With algorithm = AES_256
Encryption by password = 'Password ';
GO
OPEN encryption Ric KEY testpolicric
Decryption by password = 'Password ';
Go
SELECT
ENCRYPTBYASYMKEY (ASYMKEY_ID ('testasypolicric '), name ),
CAST (deCRYPTBYASYMKEY (ASYMKEY_ID ('testasypolicric '), ENCRYPTBYASYMKEY (ASYMKEY_ID ('testasypolicric'), name ))
As nvarchar (200 )),
ENCRYPTBYCERT (Cert_ID ('certtest'), name ),
CAST (deCRYPTBYCERT (Cert_ID ('certest'), ENCRYPTBYCERT (Cert_ID ('certest'), name ))
As nvarchar (200 )),
EncryptByKey (KEY_GUID ('testpolicric '), name ),
CAST (decryptByKey (EncryptByKey (KEY_GUID ('test10000ric '), name ))
As nvarchar (200 ))
FROM sys. objects