积极答复者
Problem restoring database with encrypted columns to different database or server with encrypted columns.

问题
-
create database test;
CREATE TABLE test(id INT IDENTITY(1,1),NAME VARCHAR(100),sn VARBINARY(256));
INSERT INTO dbo.test
( NAME)
SELECT '23cao'
UNION
SELECT 'cxp'
UNION
SELECT 'ferrero11'
UNION
SELECT '12cxp'
UNION
SELECT '2cao'
UNION
SELECT 'ferrero'
UNION
SELECT 'test20120315'CREATE CERTIFICATE testCert
ENCRYPTION BY PASSWORD = '3caNpGybRZmkbwnt1Y0Pih'
WITH SUBJECT = 'testCert',
START_DATE ='3/17/2012',
EXPIRY_DATE = '3/22/2012'CREATE SYMMETRIC KEY
testCert_Key AUTHORIZATION EncryptUser WITH
ALGORITHM= AES_128
ENCRYPTION BY CERTIFICATE testCertback this database, restore to new database.
OPEN SYMMETRIC KEY testCert_Key DECRYPTION BY CERTIFICATE
testCert WITH password='3caNpGybRZmkbwnt1Y0Pih';
SELECT NAME,sn, CAST(DECRYPTBYKEY(sn) AS VARCHAR)
FROM testCLOSE SYMMETRIC KEY testCert_Key;
query data, data is fine.
if i want to modified expired for certificate, after done,
OPEN SYMMETRIC KEY testCert_Key DECRYPTION BY CERTIFICATE
testCert WITH password='3caNpGybRZmkbwnt1Y0Pih';
SELECT NAME,sn, CAST(DECRYPTBYKEY(sn) AS VARCHAR)
FROM testCLOSE SYMMETRIC KEY testCert_Key;
all CAST(DECRYPTBYKEY(sn) AS VARCHAR) column are null.
question: why? how to do, not lost encryption data to modified certificate ?
答案
-
This is from books online:
Requirement for Restoring an Encrypted Database
To restore a database that is encrypted, you must have access to the
certificate or asymmetric key that was used to encrypt the database. Without the
certificate or asymmetric key, the database cannot be restored. As a result, the
certificate that is used to encrypt the database encryption key must be retained
as long as the backup is needed.</content>That means you can't modify certificate on target server. If need change expiry date, should do it on source server then restore to target server again. </content>
- 已编辑 rmiao 2012年3月17日 17:17
- 已标记为答案 Molly Chen_Moderator 2012年3月28日 7:47
全部回复
-
CREATE CERTIFICATE testCert
ENCRYPTION BY PASSWORD = 'aaaaaa'
WITH SUBJECT = 'testCert',
START_DATE ='5/13/2011',
EXPIRY_DATE = '3/12/2014'CREATE SYMMETRIC KEY
testCert_Key AUTHORIZATION EncryptUser WITH
ALGORITHM= AES_128,
KEY_SOURCE=‘test KeySource',
IDENTITY_VALUE = ’ test IdentityValue'
ENCRYPTION BY CERTIFICATE testCert在这台服务器这个database中,我并没有创建database master key。 当备份此数据库,还原到另外一台server。打开表,用原来的证书打开可以看到数据。如果此时重新在这台server上创建新证书。仅修改expiry—date其余属性和原来一致,创建完成后,无法看到原来表的解密数据了,有没有什么办法可以看到啊 ?
- 已合并 Molly Chen_Moderator 2012年3月19日 2:06 相同的问题
-
我要以哪种方式进行备份?
BACKUP CERTIFICATE sales05 TO FILE = 'c:\storedcerts\sales05cert' WITH PRIVATE KEY ( FILE = 'c:\storedkeys\sales05key' , ENCRYPTION BY PASSWORD = '997jkhUbhk$w4ez0876hKHJH5gh' ); GO
or
BACKUP CERTIFICATE sales09 TO FILE = 'c:\storedcerts\sales09cert' WITH PRIVATE KEY ( DECRYPTION BY PASSWORD = '9875t6#6rfid7vble7r' , FILE = 'c:\storedkeys\sales09key' , ENCRYPTION BY PASSWORD = '9n34khUbhk$w4ecJH5gh' ); GO
-
你好,
请问CERTIFICATE 中的PK是否加密了呢? 是的话就用下面语句:
BACKUP CERTIFICATE sales09 TO FILE = 'c:\storedcerts\sales09cert' WITH PRIVATE KEY ( DECRYPTION BY PASSWORD = '9875t6#6rfid7vble7r' , FILE = 'c:\storedkeys\sales09key' , ENCRYPTION BY PASSWORD = '9n34khUbhk$w4ecJH5gh' ); GO
如果你要加密CERTIFICATE 和PK 就用另外一个语句。
BACKUP CERTIFICATE : http://msdn.microsoft.com/en-us/library/ms178578(v=sql.100).aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
-
This is from books online:
Requirement for Restoring an Encrypted Database
To restore a database that is encrypted, you must have access to the
certificate or asymmetric key that was used to encrypt the database. Without the
certificate or asymmetric key, the database cannot be restored. As a result, the
certificate that is used to encrypt the database encryption key must be retained
as long as the backup is needed.</content>That means you can't modify certificate on target server. If need change expiry date, should do it on source server then restore to target server again. </content>
- 已编辑 rmiao 2012年3月17日 17:17
- 已标记为答案 Molly Chen_Moderator 2012年3月28日 7:47
-