Decrypts data with the private key of a certificate.
Transact-SQL Syntax Conventions
DecryptByCert ( certificate_ID , { 'ciphertext' | @ciphertext } [ , { 'cert_password' | @cert_password } ] )
Is the ID of a certificate in the database. int.
Is a string of data that has been encrypted with the public key of the certificate.
Is a variable of type varbinary that contains data that has been encrypted with the certificate.
Is the password that was used to encrypt the private key of the certificate. Must be Unicode.
Is a variable of type nchar or nvarchar that contains the password that was used to encrypt the private key of the certificate. Must be Unicode.
varbinary with a maximum size of 8,000 bytes.
This function decrypts data with the private key of a certificate. Cryptographic transformations that use asymmetric keys consume significant resources. Therefore, EncryptByCert and DecryptByCert are not suited for routine encryption of user data.
The following example selects rows from [AdventureWorks].[ProtectedData04] that are marked as data encrypted by certificate JanainaCert02. The example decrypts the ciphertext with the private key of certificate JanainaCert02, which it first decrypts with the password of the certificate, pGFD4bb925DGvbd2439587y. The decrypted data is converted from varbinary to nvarchar.
[AdventureWorks].[ProtectedData04]
data encrypted by certificate JanainaCert02
JanainaCert02
pGFD4bb925DGvbd2439587y
SELECT convert(nvarchar(max), DecryptByCert(Cert_Id('JanainaCert02'), ProtectedData, N'pGFD4bb925DGvbd2439587y')) FROM [AdventureWorks].[ProtectedData04] WHERE Description = N'data encrypted by certificate '' JanainaCert02'''; GO