September 29, 2009 at 1:23 pm
I was unsure of how to do this so i done some googling and a few tests of my own, and although i am successful, i have a few questions. heres what i did:
On Instance 1 I created a master key, created a server cert, backed up the server cert and encrypted it with a password. I then created a db encryption key using the server cert and enabled TDE, and took a backup. no problems
use master
GO
--create master key
create master key encryption by password = 'strong_Passw0rD'
GO
--create server certificate
Create certificate ServerCert with subject = 'server cert for use with TDE'
GO
--backup server cert, encrypting it by password
Backup certificate ServerCert to file = 'C:\cert_Backups\servercert.cer'
with private key (file = 'C:\cert_Backups\servercert.key',encryption By Password = 'strong_Passw0rD')
go
use security_testing
GO
--create db encryption key which is encrypted by the serverCert
create database encryption key with algorithm = AES_128
encryption by server certificate ServerCert
GO
--enable encryption
Alter database security_testing
set encryption on
GO
--backup encrypted database
backup database security_testing
to disk = 'C:\cert_Backups\db_bak\security_testing_encrypted_bak.bak'
On instance 2, i tried to restore the backup, this failed, so i created a new server master key, and then restored the server cert and had no problems restoring the backup:
--try to restore database on 2nd instance
RESTORE DATABASE [TDE_Restore] FROM DISK = N'C:\cert_Backups\db_bak\security_testing_encrypted_bak.bak' WITH FILE = 1,
MOVE N'Security_Testing' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore.mdf',
MOVE N'Security_Testing_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore_1.LDF', NOUNLOAD, STATS = 10
GO
--cannot restore database.
--trying to restore keys first.
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'TDEtesting123'
GO
CREATE CERTIFICATE serverCert FROM FILE = 'C:\cert_Backups\servercert.cer'
WITH PRIVATE KEY (FILE = 'C:\cert_Backups\servercert.key', DECRYPTION BY PASSWORD = 'strong_Passw0rD')
GO
RESTORE DATABASE [TDE_Restore] FROM DISK = N'C:\cert_Backups\db_bak\security_testing_encrypted_bak.bak' WITH FILE = 1,
MOVE N'Security_Testing' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore.mdf',
MOVE N'Security_Testing_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TDE_Restore_1.LDF', NOUNLOAD, STATS = 10
GO
--Success
My question surrounds the server master key. i thought i should have to backup the server master key from instance 1 and restore it to instance 2 in order to be able to restore the server cert and thus the database. as you can see above, i dont, as i created a completely new server master key on instance 2 with a completely different password. what is the purpose of the server master key in this case?
Question 2 is where does the Service Master Key fit into all this?
September 29, 2009 at 2:02 pm
If my understanding is correct, Master key just protect the private key of certificates and asymmetric keys that are present in the DB. It is the certificate that matters in TDE.
That is my understanding
-Roy
September 29, 2009 at 2:08 pm
Roy Ernest (9/29/2009)
If my understanding is correct, Master key just protect the private key of certificates and asymmetric keys that are present in the DB. It is the certificate that matters in TDE.That is my understanding
to protect the cert from what though? If i have the cert and the password to decrypt the cert, theres no way a master key can protect it, but the master key is still required to create the server certificate ( and prob keys in the db, have not checked this yet though).
October 17, 2013 at 4:17 am
Master key is created at instance level and hence it is absolutely OK to create a master key for the destination database instance which you did.
The Certificate and Keys becaked up from the source database server are the ones that will be used to encrypt.
March 9, 2015 at 4:01 am
Please check the below link for restoring with server master key.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply