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:
CREATE MASTER KEY
ENCRYPTION BY PASSWORD = 'Pass@word1';
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:
CREATE CERTIFICATE TDECert
WITH SUBJECT = 'TDE Certificate'
Download the sample script here and experiment with TDE. The script was tested using the SQL Server 2008 February CTP which you can download here.
It is important to emphasize that TDE only encrypts the content of data and log files. It does not encrypt the data as it is being passed between the client and the database server. There are many aspects to securing SQL Server; a good starting point is the Books on Line topic Securing SQL Server.
Just a small correction. Where it says "I use the private to encrypt data and someone else must use the public key to decrypt the data", actually it's the other way around. You or anyone encrypt with the public key, and the owner of the private key decrypts with the private key.
The CREATE CERTIFICATE T-SQL command has start_date and expiry_date parameters that you can specify for the time that the certificate is valid. The default as start_date = current datetime and expiry_date = current datetime + 1 year. It's probably a good idea to at least specify the expiry_date when you create a certificate.
So how do you allow only certain users to read the databases data, even excluding syadmins? i've tried the above, and although the db gets encrypted as you'd expect, it hasnt prevented any users on the system from reading the data held in the encrypted db. how do i achieve that?
Transparent data encryption is really the solution for making sure that someone can't read the data from outside of SQL Server. In other words the data in the database files is encrypted and if you can access the file you can't read the data because you don't know how to decrypt it. The transparent part is that SQL Server automatically encrypts and decrypts the data for users who have permission to access it.
User premissions can be handled n SQL Server Management Studio. Connect to a SQL Server instance then expand the Security node in the Object Explorer. The security model begins with logins that are given certain roles and access to databases, tables, stored procedures, etc.
If we encrypt a particular column in a table.. then is there a way to find before running script, data is Encrypted or decrypted in script. Problem is if data is decrypted and use to decrypted it agian it returns null. If perfom update to decrypt data (Encrypt/Decrypt update on same column) on same column all data get lost. So if somehow i can find in script that data is decrypted, we can bypass decryption step so data will not lost. Currenly using 'YES'/'NO' flag in some Reference table.
Sunday, October 14, 2012 - 8:23:39 AM - Ray Barley
This tip covered transparent data encryption which is at the database level.
As best as I can tell there is no way to determine whether a column of data is encrypted when you are using the built-in ENCRYPTBY functions in SQL Server. I think your only choice is a custom solution. You could stored procedures for all of your selects, inserts and updates so that you are certain that the column is encrypted on every insert and update and decrypted on every select. Maybe you could use a trigger to make sure that the column get encrypted on every insert and update.
Sunday, November 18, 2012 - 11:13:54 PM - Bhudev Arya
How i will make a connection string in visyal studio 2010 application to connect Encrypted Database. I want to know that after encrypted database the name of Table, its columns, stored procedure's name and their defination will be encrype or it will as readable by anyone.
Monday, November 19, 2012 - 3:32:56 PM - Ray Barley
Hey Ray. This is teriffic. Thanks for the clear explanations. I'm basically a programmer, but a complete newbie when it comes to Security and Encryption. We have a number of at rest databases in the organization I work for which are only used for internal purposes through in house developed applications. We want to provide some level of security since at the moment we have none :-) It sounds like TDE would be a good first step at providing protection to our data without impacting the applications. Is this a correct assumption?
Also and please forgive this stupid question, but are there easy ways to protect data that flows from an application to a database through let's say an update statement? In other words if I have a simple ASP application running on a Server within our organization (no external facing) and enter my name and address in a form and then click OK to submit that data to the database, is my name and address being sent as plain text from the application server to the database server.
I was wondering if there is anything I need to do when moving a server with encrypted databases from one domain to a new domain. Should I remove encryption of all the databases, move the server to the new domain, and then encrypt the databases again?
Thursday, January 24, 2013 - 10:20:10 AM - Ray Barley