sql-server - 如何在 SQL Server 中加密函数

标签 sql-server function encryption

如何加密 SQL Server 中的函数,使其不能被其他用户编辑?提前致谢。

最佳答案

使用ENCRYPTION选项:

CREATE FUNCTION testFunction ()
RETURNS int
WITH ENCRYPTION
AS
BEGIN
RETURN 1
END

这意味着定义不会存储在任何易于阅读的地方,例如:

SELECT m.definition
FROM sys.sql_modules m
JOIN sys.objects o 
on M.object_id = o.object_id AND o.type = 'FN' AND o.name = 'testFunction'

将返回 null,如果用户(甚至 sysadmin)尝试使用 SSMS 修改函数,他们将收到一个 MessageBox,说明文本已加密且无法检索。但是,根据 MSDN ,

The definition of functions created by using the ENCRYPTION option cannot be viewed by using sys.sql_modules; however, other information about the encrypted functions is displayed.

Applies to: SQL Server 2008 through SQL Server 2016.

Indicates that the Database Engine will convert the original text of the CREATE FUNCTION statement to an obfuscated format. The output of the obfuscation is not directly visible in any catalog views. Users that have no access to system tables or database files cannot retrieve the obfuscated text. However, the text will be available to privileged users that can either access system tables over the DAC port or directly access database files. Also, users that can attach a debugger to the server process can retrieve the original procedure from memory at runtime. For more information about accessing system metadata, see Metadata Visibility Configuration.

Using this option prevents the function from being published as part of SQL Server replication. This option cannot be specified for CLR functions.

您仍应确保维护适当的权限以处理此类情况。您可以更深入地阅读 here .

最后,如果这意味着要发送给您不希望能够访问源的客户端,那么如果他们真的很持久(使用调试器)。

关于sql-server - 如何在 SQL Server 中加密函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35282389/

相关文章:

mysql - SQL 在每个 SELECT 请求中获取 ROW_NUMBER 和 COUNT

sql - 事务会阻止其他代码读取不一致的数据吗?

c - 为什么 call 函数中的 if else 不适用于 do while 函数?

c# - 无法使用 C# 解密使用 PHP 加密的数据 (Rijdael-128)

c# - 性能 : . Join 与 .Contains - Linq to Entities

sql-server - 数据库托管,从 RPi python 控制台控制

php - PDO 不在函数内工作

javascript - 将节点移动到某个位置而不拖动

php - WordPress MD5 密码

vb.net - VB.net 中的密码学 - 解密文件比源文件大?