One, the encryption process
(1) Switch to master:
Use master;
(2) Create a master key based on a custom password:
CREATE MASTER KEY Encryption by PASSWORD = ' password ';
(3) Create a master key certificate, subject to any of the fields:
CREATE CERTIFICATE certificate name with SUBJECT = ' test subject ';
(4) switch to the library under which you want to encrypt:
Use user database;
(5) Create a database key based on the encryption algorithm and certificate:
CREATE DATABASE encryption KEY with algorithm = aes_128 encryption by SERVER CERTIFICATE certificate name;
(6) Turn on the encryption state of the library:
ALTER database SET encryption on;
------------------------------------------------------------------
Second, backup and restore
(1) The Backup master key is in the specified directory:
BACKUP MASTER KEY to FILE = ' d:\storedkeys\weifang\masterkey ' encryption by PASSWORD = ' Password '
(2) Backup certificate:
BACKUP CERTIFICATE certificate name to FILE = ' d:\storedcerts\weifang\sdjslcert '; :
(3) Restore master key:
Use master
RESTORE MASTER KEY from FILE = ' D:\storedkeys\weifang\masterkey '
Decryption by PASSWORD = ' Password '
Encryption by PASSWORD = ' password ';
--because I still have the original certificate here, so I will prompt the following information:
--the old and new master keys is identical. No data re-encryption is required.
(4) Restore certificate
CREATE CERTIFICATE Card Title
From FILE = ' D:\storedcerts\sdjslcert '
GO
--Because the certificate already exists, the following information is prompted:
--A Certificate with Name ' MyServerCert2 ' already exists or this certificate already have been added to the database.
It is important to note that certificates are not differentiated according to the title of the certificate. My original certificate name is Myservercert, the certificate created here is named MyServerCert2, but it is a backup from Myservercert, or an error.
SQL Server transparent Data encryption