Encryption in MS SQL

MSSQL-Feature-Image

We create the following table for testing encryption.
Value column keep plaintext value
EN_C column keep value which is encrypted by Certificate
EN_SY column keep value which is encrypted by Symmetric Key
EN_AY column keep value which is encrypted by Asymmetric Key

Encrypt value
Using “ENCRYPTBYCERT(CERT_ID(‘)” to encrypt data by certificate.
Using “ENCRYPTBYKEY(Key_GUID(‘)” to encrypt data by Symmetric key.
Using “ENCRYPTBYASYMKEY(ASYMKEY_ID(‘)” to encrypt data by Asymmetric key.

Decrypt value
The decrypted value need to convert as varchar.

Post related to Server Master Key
Post related to Database Master Key
Post related to Certificates
Post related to Asymmetric Keys
Post related to Symmetric Keys

Author: Joe Chan