码迷,mamicode.com
首页 > 数据库 > 详细

数据库加密&证书创建

时间:2014-09-12 10:00:33      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   文件   数据   div   sp   log   

以下是用sqlserver给数据库进行加密的脚本,其中当然也包含了证书创建的步骤:

USE master;
GO   
--drop master key
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 123456;  
GO

BACKUP MASTER KEY TO FILE = D:\SQL1_master.key ENCRYPTION BY   
PASSWORD = 123456;  
GO    
CREATE CERTIFICATE TDECert WITH SUBJECT = TDE Certificate;  
GO

BACKUP CERTIFICATE TDECert TO FILE = D:\SQL1_master.cer   
WITH PRIVATE KEY (   
FILE  = D:\SQL1_TDECert.pvk,   
ENCRYPTION BY PASSWORD = 123456   
    );  

USE TEST;   
GO   
CREATE DATABASE ENCRYPTION KEY   
WITH ALGORITHM = AES_128   
ENCRYPTION BY SERVER CERTIFICATE TDECert;

GO
ALTER DATABASE TEST SET ENCRYPTION ON


--如果需要还原加密后的数据库文件到另外一台服务器,需要首先还原证书到目标服务器:
--目标服务器的master key 可以跟原服务器的不一样
USE master;   
CREATE CERTIFICATE TDECert FROM FILE = D:\SQL1_master.cer   
      WITH PRIVATE KEY (   
        FILE  = D:\SQL1_TDECert.pvk,   
        DECRYPTION BY PASSWORD = 123456   
    );  

数据库加密&证书创建

标签:style   blog   color   io   文件   数据   div   sp   log   

原文地址:http://www.cnblogs.com/shihuai355/p/3967686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!