Home Database Mysql Tutorial 透明数据加密(TDE)库的备份和还原

透明数据加密(TDE)库的备份和还原

Jun 07, 2016 pm 06:07 PM

对于包含敏感数据的库,要实现备份加密。即备份文件别人拿到也不能还原和查看其中的数据

想到TDE(Transparent Data Encryption)。

TDE MSDN 说明:

“透明数据加密”(TDE) 可对数据和日志文件执行实时 I/O 加密和解密。这种加密使用数据库加密密钥 (DEK),该密钥存储在数据库引导记录中以供恢复时使用。DEK 是使用存储在服务器的 master 数据库中的证书保护的对称密钥,或者是由 EKM 模块保护的非对称密钥。TDE 保护“处于休眠状态”的数据,即数据和日志文件。它提供了遵从许多法律、法规和各个行业建立的准则的能力。软件开发人员籍此可以使用 AES 和 3DES 加密算法来加密数据,且无需更改现有的应用程序。
其实吸引我的是“无需更改现有的应用程序”,因为我需要加密的库服务于一个非常稳定的系统,而且这样做所有事情DBA可控。

TDE加密体系结构:


测试过程:
代码如下:
--创建主密钥(Master Key)
USE master
GO
--DROP MASTER KEY
CREATE MASTER KEY ENCRYPTION BY PASSWORD=N'1qaz@WSX';
GO
--备份主密钥
BACKUP MASTER KEY TO FILE=N'C:\master_key.cer'
ENCRYPTION BY PASSWORD=N'!QAZ2wsx'
GO
--创建基于主密钥的证书。用于保护数据库加密密钥(Database Encryption Key)
--DROP CERTIFICATE SDB_Cert
CREATE CERTIFICATE SDB_Cert
WITH SUBJECT=N'Certificate for SecretDB'
go
--使用私钥加密的方式备份主密钥的证书
BACKUP CERTIFICATE SDB_Cert
TO FILE=N'C:\SDB_Cert.cer'
WITH PRIVATE KEY
(
FILE =N'C:\SDB_Cert.pvk',
ENCRYPTION BY PASSWORD='!QAZ2wsx'
)
GO
--创建测试库SecretDB
USE master
GO
CREATE DATABASE SecretDB
GO
USE SecretDB
GO
CREATE TABLE SDB_TB
(ID INT,VAL NVARCHAR(20));
INSERT INTO SDB_TB
VALUES (1,N'A'),(2,N'B'),(3,N'C');
GO
USE SecretDB
go
--创建数据库加密密钥
CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM=AES_128
ENCRYPTION BY SERVER CERTIFICATE SDB_Cert;
GO
--启用数据库加密
USE SecretDB
go
ALTER DATABASE SecretDB SET ENCRYPTION ON
go
--备份SecretDB,用于后续的异机还原测试
USE master
go
BACKUP DATABASE SecretDB TO DISK=N'D:\SecretDB.bak'
go
在完成这些后,SecretDB库已经加密,并且得到其加密后的备份文件,接下来需要在另台还原这个备份。
我把SecretDB.bak,SDB_Cert.cer,SDB_Cert.pvk拷到别一台机。直接还原的话,会报错。需要创建原来用于加密的证书来还原数据库备份。我的目的达到了!
--在异机上恢复SecretDB的备份
USE master
GO
CREATE DATABASE SecretDB
GO
RESTORE DATABASE SecretDB
FROM DISK=N'D:\SecretDB.bak'
WITH REPLACE
GO
--消息 33111,级别 16,状态 3,第 1 行
--找不到指纹为 '0x0106000000000009010000009C529FFD5C7FD72FD0AAE9EDF46C5F69946FFED0' 的服务器 证书。
--消息 3013,级别 16,状态 1,第 1 行
--RESTORE DATABASE 正在异常终止。
创建证书并还原。
USE master
GO
CREATE CERTIFICATE SDB_Cert
FROM FILE=N'C:\SDB_Cert.cer'
WITH PRIVATE KEY
(
FILE=N'C:\SDB_Cert.pvk',
DECRYPTION BY PASSWORD=N'!QAZ2wsx'
)
GO
RESTORE DATABASE SecretDB
FROM DISK=N'D:\SecretDB.bak'
WITH REPLACE
GO

总结:
其实在做TDE前应该仔细阅读BOL的说明:ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.zh-CHS/s10de_4deptrbl/html/c75d0d4b-4008-4e71-9a9d-cee2a566bd3b.htm
其中说到:
如果使用 TDE 对数据库进行加密,备份压缩将无法显著压缩备份存储。
复制不会以加密形式从启用了 TDE 的数据库中自动复制数据。如果您想保护分发和订阅服务器数据库,则必须单独启用 TDE。
某些限制和注意事项,会影响TDE的部署和使用。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

See all articles