如何在SQL Server 2005数据库之间传输sql加密数据?
时间:2020-03-06 14:53:15 来源:igfitidea点击:
我有一个现有的SQL Server 2005数据库,其中包含使用对称密钥加密的数据。使用密码打开对称密钥。我正在努力升级使用该数据库的前端应用程序,其中包括添加许多新表,存储过程,UDF等,并对现有表和数据库对象进行许多修改。为此,我正在复制现有的开发数据库,以便在进行新开发时可以独立地支持,维护和更新当前系统。
复制数据库的好方法是什么?通常,我将备份现有数据库,然后将其还原到新数据库。但是,考虑到加密数据,这是否可行?我是否仍可以使用现有的对称密钥和密码对新数据库中的数据进行加密和更重要的解密?
我可能想使用DTS仅转移现有模式。在新数据库中创建一个新的对称密钥/密码。然后编写临时查询以传输数据,使用现有密钥/密码进行解密以及使用新数据库中的新密钥/密码进行加密。
我想这的核心是,对称密钥是否适合加密/解密单个数据库中或者同一服务器上许多数据库中的数据?
解决方案
我们所指的对称密钥是数据库主密钥(DMK)。它们被保存在数据库级别,因此备份/还原到另一个SQL Server应该可以正常工作(注意不同的服务帐户,此线程暗示了这一点)
在执行任何操作之前,请确保已备份了密钥(大概已经完成了此操作):
USE myDB GO BACKUP MASTER KEY TO FILE = 'path_to_file' ENCRYPTION BY PASSWORD = 'password' GO
从这篇文章:
When you create a Database Master Key, a copy is encrypted with the supplied password and stored in the current database. A copy is also encrypted with the Service Master Key and stored in the master database. The copy of the DMK allows the server to automatically decrypt the DMK, a feature known as "automatic key management." Without automatic key management, you must use the OPEN MASTER KEY statement and supply a password every time you wish to encrypt and/or decrypt data using certificates and keys that rely on the DMK for security. With automatic key management, the OPEN MASTER KEY statement and password are not required.