=======================================================================================
/*批量加密SQLSERVER 2000 的存储过程
/*
摘自:微软官方网站
*/
=======================================================================================
下面给出了一个存储过程,它的作用是自动将当前数据库的用户存储过程加密。DECLARE @sp_name nvarchar(400)
DECLARE @sp_content nvarchar(2000)
DECLARE @asbegin int
declare @now datetime
select @now = getdate()
DECLARE sp_cursor CURSOR FOR
SELECT object_name(id)
FROM sysobjects
WHERE xtype = 'P'
AND type = 'P'
AND crdate < @now
AND OBJECTPROPERTY(id, 'IsMSShipped')=0OPEN sp_cursorFETCH NEXT FROM sp_cursor
INTO @sp_nameWHILE @@FETCH_STATUS = 0
BEGIN
SELECT @sp_content = text FROM syscomments WHERE id = OBJECT_ID(@sp_name)
SELECT @asbegin = PATINDEX ( '%AS' + char(13) + '%', @sp_content)
SELECT @sp_content = SUBSTRING(@sp_content, 1, @asbegin - 1)
+ ' WITH ENCRYPTION AS'
+ SUBSTRING (@sp_content, @asbegin+2, LEN(@sp_content))
SELECT @sp_name = 'DROP PROCEDURE [' + @sp_name + ']'
EXEC sp_executesql @sp_name
EXEC sp_executesql @sp_content
FETCH NEXT FROM sp_cursor
INTO @sp_name
ENDCLOSE sp_cursor
DEALLOCATE sp_cursor该存储过程利用了 sysobjects 和 syscomments 表,并巧妙地修改了原存储过程的 SQL 定义语句,将 AS 修改为了 WITH ENCRYPTION AS,从而达到了加密存储过程的目的。本存储过程在 SQL Server 2000 上通过。
/*批量加密SQLSERVER 2000 的存储过程
/*
摘自:微软官方网站
*/
=======================================================================================
下面给出了一个存储过程,它的作用是自动将当前数据库的用户存储过程加密。DECLARE @sp_name nvarchar(400)
DECLARE @sp_content nvarchar(2000)
DECLARE @asbegin int
declare @now datetime
select @now = getdate()
DECLARE sp_cursor CURSOR FOR
SELECT object_name(id)
FROM sysobjects
WHERE xtype = 'P'
AND type = 'P'
AND crdate < @now
AND OBJECTPROPERTY(id, 'IsMSShipped')=0OPEN sp_cursorFETCH NEXT FROM sp_cursor
INTO @sp_nameWHILE @@FETCH_STATUS = 0
BEGIN
SELECT @sp_content = text FROM syscomments WHERE id = OBJECT_ID(@sp_name)
SELECT @asbegin = PATINDEX ( '%AS' + char(13) + '%', @sp_content)
SELECT @sp_content = SUBSTRING(@sp_content, 1, @asbegin - 1)
+ ' WITH ENCRYPTION AS'
+ SUBSTRING (@sp_content, @asbegin+2, LEN(@sp_content))
SELECT @sp_name = 'DROP PROCEDURE [' + @sp_name + ']'
EXEC sp_executesql @sp_name
EXEC sp_executesql @sp_content
FETCH NEXT FROM sp_cursor
INTO @sp_name
ENDCLOSE sp_cursor
DEALLOCATE sp_cursor该存储过程利用了 sysobjects 和 syscomments 表,并巧妙地修改了原存储过程的 SQL 定义语句,将 AS 修改为了 WITH ENCRYPTION AS,从而达到了加密存储过程的目的。本存储过程在 SQL Server 2000 上通过。
这种处理对于我所举的例子p_as可以吗?
应该不可以吧!!
将存储过程中的AS修改为WITH ENCRYPTION AS
DECLARE @sp_content nvarchar(2000)
DECLARE @asbegin intdeclare @now datetime
select @now = getdate()DECLARE sp_cursor CURSOR FOR-----游标读取所有存储过程名称
SELECT object_name(id)
FROM sysobjects
WHERE xtype = 'P'
AND type = 'P'
AND crdate < @now
AND OBJECTPROPERTY(id, 'IsMSShipped')=0OPEN sp_cursorFETCH NEXT FROM sp_cursor
INTO @sp_nameWHILE @@FETCH_STATUS = 0BEGIN
SELECT @sp_content = text FROM syscomments WHERE id = OBJECT_ID(@sp_name)----读出存储过程内容
SELECT @asbegin = PATINDEX ( '%AS' + char(13) + '%', @sp_content)
SELECT @sp_content = SUBSTRING(@sp_content, 1, @asbegin - 1) ---将AS转化为with encryption as
+ ' WITH ENCRYPTION AS'
+ SUBSTRING (@sp_content, @asbegin+2, LEN(@sp_content))
SELECT @sp_name = 'DROP PROCEDURE [' + @sp_name + ']'
EXEC sp_executesql @sp_name
EXEC sp_executesql @sp_content
FETCH NEXT FROM sp_cursor
INTO @sp_name
ENDCLOSE sp_cursor
DEALLOCATE sp_cursor这个程序直接用就行的,小鸟,这就是个自动加密,根据判断用户自己存储程序来。
但其中有2个地方有点不明白:
1.好象用WITH ENCRYPTION 进行加密后,无法解密,万一以后我想看看这个储存过程代码杂整?
2.最后有个地方是DROP PROC。为什么要加这句勒,刚加密完又删除?
请高手明示
--可以解密的!用J9988的方法可以解密DROP PROC。--是删除未加密的存储过程
1、关于解密:看j9988写的存储过程:http://www.pconline.com.cn/pcedu/empolder/db/sql/0508/693684.html
2、关于drop proc,因为原存储过程已存在,故需要先drop掉,再重建(带with encrytion的)另外:
这个处理并不能自动加密我所举的例子存储过程p_as
你可以试试!!
drop proc 如何能判断该存储过程是否带with encrytion的,意思说加密后,他存储过程名字也能变?
'DROP PROCEDURE [' + @sp_name + ']'
@sp_name 这个取得是存储过程的名字嘛
请高人明示
create proc p_as
@leng int=5,--@as 故意混淆 as
@as
varchar(50)=' as
as
as
as
select '
--,@asas decimal(18,4)
as -- 就要找它的准确位置
select @leng,@as--,@asas
go
存贮过程超过8000个字符就会出错的!