The following is a script that uses SQL Server to encrypt a database, which of course contains the steps to create a certificate:
UseMaster;GO --Drop master KeyCREATEMASTERKEYEncryption byPASSWORD= '123456'; GOBACKUPMASTERKEY to FILE = 'D:\SQL1_master.key'Encryption byPASSWORD= '123456'; GO CREATECERTIFICATE Tdecert withSUBJECT= 'TDE Certificate'; GOBACKUPCERTIFICATE Tdecert to FILE = 'D:\SQL1_master.cer' withPRIVATEKEY ( FILE = 'D:\SQL1_TDECert.pvk', encryption byPASSWORD= '123456' ); UseTEST; GO CREATE DATABASEEncryptionKEY withAlgorithm=aes_128 Encryption bySERVER CERTIFICATE Tdecert;GOALTER DATABASETESTSETEncryption on--If you need to restore the encrypted database file to another server, you need to restore the certificate to the target server first:--the target server's master key can be different from the original server Usemaster; CREATECERTIFICATE Tdecert from FILE = 'D:\SQL1_master.cer' withPRIVATEKEY ( FILE = 'D:\SQL1_TDECert.pvk', decryption byPASSWORD= '123456' );
Database Encryption & Certificate creation