SQL SERVER 2008 加密和解密,这样的文件在互联网上不胜枚举,本文的寓意还是一样,一为记录,二可以为开发者提供在实现过程中的注意事项。

TDE: Transparent data encryption is the new database-level encryption feature introduced in SQL Server 2008

加密(详细点击)

1.    If it does not already exist, create a database master key (DMK) for the master database. Ensure that the database master key is encrypted by the service master key (SMK).

CREATE MASTER KEY ENCRYPTION BY PASSWORD = ‘some password’;

2.    Either create or designate an existing certificate for use as the database encryption key (DEK) protector. For the best security, it is recommended that you create a new certificate whose only function is to protect the DEK. Ensure that this certificate is protected by the DMK.

CREATE CERTIFICATE tdeCert WITH SUBJECT = ‘TDE Certificate’;

3.    Create a backup of the certificate with the private key and store it in a secure location. (Note that the private key is stored in a separate file—be sure to keep both files). Be sure to maintain backups of the certificate as data loss may occur otherwise.

BACKUP CERTIFICATE tdeCert TO FILE = ‘path_to_file’

   WITH PRIVATE KEY (

         FILE = ‘path_to_private_key_file’,

         ENCRYPTION BY PASSWORD = ‘cert password’);

4.    Optionally, enable SSL on the server to protect data in transit.

Perform the following steps in the user database. These require CONTROL permissions on the database.

5.    Create the database encryption key (DEK) encrypted with the certificate designated from step 2 above. This certificate is referenced as a server certificate to distinguish it from other certificates that may be stored in the user database.

CREATE DATABASE ENCRYPTION KEY

   WITH ALGORITHM = AES_256

   ENCRYPTION BY SERVER CERTIFICATE tdeCert

6.    Enable TDE. This command starts a background thread (referred to as the encryption scan), which runs asynchronously.

ALTER DATABASE myDatabase SET ENCRYPTION ON

简而言之,就是先创建自己的Master key, 然后创建CERTIFICATE证书,然后备份证书,接着关联Master Key 和CERTIFICATE,然后就是设置数据库SET ENCRYPTION ON.
按照步骤下来,你就可以利用下面的这段话来看,是否加密成功。当然,你也可以一开始就去先做判断。

---查看db_name是否加密,------------
---- is_encrypted=1表示加密---------
---- is_encrypted=0表示未加密-------
SELECT is_encrypted FROM sys.databases
WHERE name ='db_name'

解密:

  删除Master key

  

ALTER DATABASE db_name;
SET ENCRYPTION OFF;
GO
/* Wait for decryption operation to complete, look for a
value of 1 in the query below. */
SELECT encryption_state
FROM sys.dm_database_encryption_keys;
GO
USE db_name;
GO
DROP DATABASE ENCRYPTION KEY;
GO

  在删除Master key的时候,首先要设置SET ENCRYPTION OFF,然后使用DROP DATABASE ENCRYPTION KEY删除,如果数据库的数据或是结构有变化的话,SQL Management Studio会提示让你去备份数据库日志文件Backup log AdventureWorks2012 set disk="物理地址"。

  删除CERTIFICATE

  OK

完成之后,在SQL Management Stud中测试时,无论附加还是还原,需要注意的是,这里如果有了3241,我们仍然可以使用SQL Script的方式进行测试。

SQL SERVER 2008 使用TDE加密和解密的更多相关文章

  1. SQL Server 2008, 2008 R2, 2012 and 2014 完全支持TLS1.2加密传输

    SQL Server 2008, 2008 R2, 2012 and 2014 完全支持TLS1.2加密传输 微软高兴地宣布所有主流SQL Server客户端驱动和SQL Server发行版已经支持T ...

  2. 在SQL Server 2008中执行透明数据加密

    问题 安全是任何公司的一个主要考量.数据库备份容易被偷并被恢复到另一个SQL Server实例上.当我们浏览SQL Server 2008的新特性时,我们对一个叫做透明数据加密的特性很感兴趣,我们可以 ...

  3. SQL Server 2008连接字符串写法大全

    一..NET Framework Data Provider for SQL Server 类型:.NET Framework类库使用:System.Data.SqlClient.SqlConnect ...

  4. SQL Server 2008连接字符串写法大全{转}

    一..NET Framework Data Provider for SQL Server 类型:.NET Framework类库使用:System.Data.SqlClient.SqlConnect ...

  5. SQL Server 2008连接字符串写法大全(摘自网络)

    一..NET Framework Data Provider for SQL Server 类型:.NET Framework类库使用:System.Data.SqlClient.SqlConnect ...

  6. 《SQL Server 2008从入门到精通》--20180716

    1.锁 当多个用户同时对同一个数据进行修改时会产生并发问题,使用事务就可以解决这个问题.但是为了防止其他用户修改另一个还没完成的事务中的数据,就需要在事务中用到锁. SQL Server 2008提供 ...

  7. SQL Server 2008安全加固手册

    1.身份鉴别 1.1避免使用空密码和弱口令 要求:应对登录操作系统和数据库系统的用户进行身份标识和鉴别. 目的:操作系统和数据库系统管理用户身份鉴别信息应具有不易被冒用的特点,口令应有复杂度要求并定期 ...

  8. 利用SQL Server 2008 R2创建自动备份计划

    本文主要利用SQL Server 2008 R2自带的"维护计划"创建一个自动备份数据的任务. 首先,启动 Sql Management studio,确保"SQL Se ...

  9. SQL Server 2008 阻止保存要求重新创建表的更改问题的设置方法

    不是很理解为什么在2008中会加入阻止保存要求重新创建表的更改这个选项.症状表现为修改表结构的时候会"阻止"你.而且我遇到的情况是居然有的时候阻止你,有的时候不阻止你,摸不到头脑. ...

随机推荐

  1. CentOS忘记root密码的解决方法

    1.在开机启动的时候按键盘上的“E”键 或者“ESC”键,会进入如下界面. 2. 选择相应的内核,一般都是第二个选项,再次按“E”,出现下图,选择第二项,再次按“E”键 3. 经过第二步,这个画面可以 ...

  2. _blank开新窗体不符合标准?

    我们要在新窗体中打开链接通常的做法是在链接后面加target="_blank",我们採用过渡型的DOCTYPE(xh tml1-transitional. dtd)时没有问题,可是 ...

  3. MYSQL在线注释文档--- 在gdb中显示源码(gdbtui使用方法)----赖明星的个人博客

    http://mingxinglai.com/cn/2013/07/gdbtui/ MySQL源码注释与类图 http://mingxinglai.com/cn/2015/08/mysql-annot ...

  4. 调用iframe 中的js[兼容各种浏览器]

    *chrome浏览器需要在服务器环境中测试 <!DOCTYPE html> <html> <head> <meta http-equiv="cont ...

  5. 《c和指针》1.5编程练习问题

    <c和指针>1.5编程练习问题 #include<stdio.h>#include<stdlib.h>#include<string.h>#define ...

  6. 【转载】NIO服务端序列图

    步骤一:打开ServerSocketChannel,用于监听客户端的连接,它是所有客户端连接的父管道,代码示例如下: ServerSocketChannel acceptorSvr = ServerS ...

  7. C#扫盲之:String字符串的常用方法和冷知识

    前言 字符串对于任何编程语言都是必须操作和了解的,因为在实际编程中,任何项目和工程都必须要处理字符串数据,文件路径.提示消息,文本的处理等等,而在使用过程中很多人都是没有系统的了解,大量使用strin ...

  8. ECMA5 Array 新增API reduce

    1)reduce:相当与迭代: [].reduce(function(previous,current,index,array){ return previous * current;//相当与做阶乘 ...

  9. Unity3D 之UGUI 切换开关(toggle)

    (toggle)开关能够实现通过点击实现开和关. 开关下面有两个游戏元素,一个是背景,一个是文字,背景是开关按钮的背景. 可以通过 Is ON开控制开关的开与关. Group -->分组,能够实 ...

  10. swift变量交换赋值

    重点在& func jiaohuan(inout a: Int,inout b: Int) { let temp = a a = b b = temp } jiaohuan(&aa,b ...