join the MSSQLTips community

Today's Site Sponsor


 

SQL Compare quickly and easily compares and synchronizes SQL Server database schemas
 




SQL Server 2008 Transparent Data Encryption getting started

Written By: Ray Barley -- 6/6/2008 -- read/post comments -- print -- Bookmark and Share

Rating: (not rated yet) Rate

Problem
While reviewing the new features in SQL Server 2008, we noticed Transparent Data Encryption.  This sounds very interesting.  Could you provide us with an explanation and the details to implement it?

Solution
TDE is a new feature in SQL Server 2008; it provides real time encryption of data and log files.  Data is encrypted before it is written to disk; data is decrypted when it is read from disk.  The "transparent" aspect of TDE is that the encryption is performed by the database engine and SQL Server clients are completely unaware of it.  There is absolutely no code that needs to be written to perform the encryption and decryption.  There are a couple of steps to be performed to prepare the database for TDE, then the encryption is turned on at the database level via an ALTER DATBASE command.

We've probably all heard of incidents where backup tapes containing sensitive information have been lost or stolen.  With TDE the backup files are also encrypted when using just the standard BACKUP command once encryption is turned on for the database.  The data in the backup files (or on disk) is completely useless without also having access to the key that was used to encrypt the data.

Before we dive in to the steps to implement TDE, let's take a minute to discuss encryption at a very high level.  The Wikipedia definition of encryption is "the process of transforming information (referred to as plaintext) using an algorithm (called cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key".  To encrypt some data, I choose an available algorithm, supply a key and I now have encrypted data.  To decrypt the encrypted data, I choose the same algorithm and supply the key.  The security provided by encryption is based on the strength of the algorithm and protection of the key.  There are two types of keys - symmetric and asymmetric.  With a symmetric key, the same value is used to encrypt and decrypt the data.  An asymmetric key has two components - a private key and a public key.  I use the private to encrypt data and someone else must use the public key to decrypt the data.  To recap, the symmetric key or private key of the asymmetric key pair must be stored securely in order for encryption to be effective.

Now let's walk through an example of how to implement TDE.  Books on Line lists the following four steps to implement TDE on a particular database:

  • Create a master key
  • Create or obtain a certificate protected by the master key
  • Create a database encryption key and protect it by the certificate
  • Set the database to use encryption

Create a Master Key

A master key is a symmetric key that is used to create certificates and asymmetric keys.  Execute the following script to create a master key:

USE master;
CREATE MASTER KEY 
ENCRYPTION BY PASSWORD = 'Pass@word1';
GO

Note that the password should be a strong one (i.e. use alpha, numeric, upper, lower, and special characters) and you have to backup (use BACKUP MASTER KEY) and store it in a secure location.  For additional details on master keys refer to our earlier tip Managing SQL Server 2005 Master Keys for Encryption.

Create a Certificate

Certificates can be used to create symmetric keys for data encryption or to encrypt the data directly.  Execute the following script to create a certificate:

USE master;
CREATE CERTIFICATE TDECert 
WITH SUBJECT = 'TDE Certificate'
GO

Note that certificates also need to be backed up (use BACKUP CERTIFICATE) and stored in a secure location.  For additional details on certificates, refer to our earlier tip SQL Server 2005 Encryption - Certificates 101.

Create a Database Encryption Key

A database encryption key is required for TDE.  Execute the following script to create a new database and a database encryption key for it:

CREATE DATABASE mssqltips_tde
GO
USE mssqltips_tde;
CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = AES_256
ENCRYPTION BY SERVER CERTIFICATE TDECert
GO

In order to work with TDE the encryption key must be encrypted by a certificate (a password will not work) and the certificate must be located in the master database. 

Enable TDE

The final step required to implement TDE is to execute the following script:

ALTER DATABASE mssqltips_tde
SET ENCRYPTION ON
GO
SELECT [name], is_encrypted FROM sys.databases
GO

You can query the is_encrypted column in sys.databases to determine whether TDE is enabled for a particular database.

Next Steps

Readers Who Read This Tip Also Read Free Live Webcast Comment or Ask Questions About This Tip


Sponsor Information
Free SQL Server performance monitoring dashboard – Idera SQL check

Try SQL Object Level Recovery Native from Red Gate to save time and disk space. Download a free trial.

We fill in the gaps... SQL Server Training, Development, Performance Tuning, SSIS and more

Follow MSSQLTips on Twitter!

Learn SQL Server 2008, Performance Tuning, Development, Administration, DR, Replication and more from these web casts


Get Our Tips Newsletter

We keep 50,000+ SQL Server professionals informed.



Red Gate Software - SQL Prompt

How can he write SQL so fast? Some developers write SQL amazingly fast. Do you want to know their secret? It’s SQL Prompt. “This is a must-have tool for all T-SQL developers.” Brian Brewder, Brian Online.

Download now!

More SQL Server Tools
SQL Refactor

SQL Backup

SQL diagnostic manager

SQL comparison toolset

SQL secure




Copyright (c) 2006-2010 Edgewood Solutions, LLC All rights reserved
privacy statement | disclaimer | copyright | advertise | write for mssqltips | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


CareerQandA.com | MSSharePointTips.com | MSSQLTips.com