having problems trying to restore encrypted databa

2020-02-07 05:29发布

问题:

Im trying to copy an encrypted database from the default server to my server for testing purposes

but im having troubles doing so because i have never done it so im going to explain my procedure and the errors i got

first i create a master key :

USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='DB-PaSSw0rD'
GO

all is good for now :
Command(s) completed successfully.

then i create a certificate by importing the certificate created on the default server:

CREATE CERTIFICATE TDECERT
FROM FILE = 'C:\temp\TDECert.cer'
WITH PRIVATE KEY (FILE = 'C:\temp\TDECertKey.pvk' , 
DECRYPTION BY PASSWORD ='pAssW0rD')
GO

but i get :
Msg 15581, Level 16, State 1, Line 1

Please create a master key in the database or open the master key in the session before performing this operation.

to resolve this i try to open the master key:

OPEN MASTER KEY DECRYPTION BY PASSWORD ='DB-PaSSw0rD'
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY

but i get : Cannot find the symmetric key 'master key', because it does not exist or you do not have permission.

then to resolve this second issue i try to grant it access:

GRANT CONTROL ON CERTIFICATE :: TDECERT To Administrator

but i get :
Cannot find the certificate 'TDECERT', because it does not exist or you do not have permission.

thanks in advance for ur time

回答1:

problem solved

all i had to do is add

USE master

before

CREATE CERTIFICATE TDECERT
FROM FILE = 'C:\temp\TDECert.cer'
WITH PRIVATE KEY (FILE = 'C:\temp\TDECertKey.pvk' , 
DECRYPTION BY PASSWORD ='pAssW0rD')
GO

and didnt need anything else

that easy!