有没有办法将加密脚本插入SQL Server数据库? [英] Is there a way to insert an encrypted script into a SQL Server database?
问题描述
我的公司认为数据库脚本是我们的知识产权的一部分。
My company considers database scripts we write part of our intellectual property.
对于新版本,我们为用户提供了两部分设置:
With new releases, we deliver a 2-part setup for our users:
- 一个桌面应用程序
- 一个包含初始化/更新数据库的复杂性的可执行文件(RedGate SQL Packager)
我知道一旦脚本存在,我可以对数据库中的存储过程进行加密,但是有什么办法可以以加密形式插入 ?我不希望纯文本能够跨越线(或更准确地说,在SQL脚本可执行文件和服务器之间)被拦截。
I know I can encrypt a stored procedure on a database once the script is present, but is there any way to insert it in an encrypted form? I don't want plain-text to be able to be intercepted across the "wire" (or more accurately, between the SQL script executable and the server).
I 我并没有把它与我们正在使用的工具绑在一起 - 我只是想知道是否可以而不用诉诸于某种东西。
I'm not really tied to the tool we're using - I just want to know if it's possible without having to resort to something hokey.
推荐答案
尝试使用 Enctyptpassphrase 和 DecryptPassPharse 函数。
使用ENCRYPTBYPASSPHRASE对服务器上的所有DDL语句和DECRYPTBYPASSPHRASE进行解密和执行。
Use ENCRYPTBYPASSPHRASE to encrypt all your DDL statements and then DECRYPTBYPASSPHRASE on the server to decrypt and execute.
declare @encrypt varbinary(200)
select @encrypt = EncryptByPassPhrase('key', 'your script goes here' )
select @encrypt
select convert(varchar(100),DecryptByPassPhrase('key', @encrypt ))
创建一个程序看起来像这样
Create a procedure that would look like this
CREATE PROCEDURE DBO.ExecuteDDL
(
@script varbinary(max)
)
AS
BEGIN
DECLARE @SQL nvarchar(max)
SET @SQL = (select convert(varchar(max),DecryptByPassPhrase('key', @script )))
EXECUTE sp_executesql @SQL
END
一旦这样,您可以将脚本发布到您的服务器,如下所示
Once this is in place you can publish scripts to your server like this
这篇关于有没有办法将加密脚本插入SQL Server数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!