DECRYPTBYKEY
cryptographic transform or key lookup
What changes
- Input
- plaintext or ciphertext and a key, certificate or passphrase
- Output or change
- ciphertext, plaintext, hash, signature check, or key metadata
- Return type
- varbinary, with a maximum size of 8,000 bytes. DECRYPTBYKEY returns NULL if the symmetric key used for data encryption isn't open or if ciphertext is NULL.
Syntax at a glance
DECRYPTBYKEY ( { 'ciphertext' | @ciphertext } [ , add_authenticator , { authenticator | @authenticator } ] )
Work example
Decrypt existing bytes with an opened symmetric key in its documented scope.
Use synthetic data in an isolated database. Follow the existing key hierarchy and keep keys and plaintext out of output.
Check your work A closed or unavailable key can return null, which differs from empty plaintext.
Open Microsoft Learn for full syntax, permissions, and details for your version.