sqlServer存储过程的加密和解密方法

sql存储过程的加密和解密
★加密存储过程:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'encrypt_this' AND type = 'P')  DROP PROCEDURE encrypt_this
GO
USE pubs
GO
CREATE PROCEDURE encrypt_this
WITH ENCRYPTION  ---只需要在创建时加入WITH ENCRYPTION即可
AS
SELECT * FROM authors
GO
--查看存储过程文本:
EXEC sp_helptext encrypt_this
下面是结果集:
The object's comments have been encrypted.  ----对象已经被加密
★解密存储过程:
CREATE  PROCEDURE sp_decrypt(@objectName varchar(50)) 
AS 
begin 
set nocount on 
--CSDNj9988 copyright:2004.04.15 
--V3.1 
--破解字节受限制,适用于SQLSERVER2000存储过程,函数,视图触发器 
--修正上一版视图触发器不能正确解密错误回龙观北郊医院 
--发现有错,请E_MAILCSDNj9988@tom  妈妈的恶作剧
begin tran 
declare @objectname1 varchar(100),@orgvarbin varbinary(8000) 
declare @sql1 nvarchar(4000),@sql2 varchar(8000),@sql3 nvarchar(4000),@sql4 nvarchar(4000) 
乩童DECLARE  @OrigSpText1 nvarchar(4000),  @OrigSpText2 nvarchar(4000) , @OrigSpText3 nvarchar(4000), @resultsp nvarchar(4000) 
declare  @i int,@status int,@type varchar(10),@parentid int 
declare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number int 
select @type=xtype,@parentid=parent_obj from sysobjects where id=object_id(@ObjectName) 
 
create table  #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int) 
insert #temp SELECT number,colid,ctext,encrypted,status FROM syscomments  WHERE id = object_id(@objectName) 
select @number=max(number) from #temp 
set @k=0 
 
while @k<=@number 
begin 
if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k) 
begin 
if @type='P' 
set @sql1=(case when @number>1 then 'ALTER PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS ' 
                          else 'ALTER PROCEDURE '+ @objectName+' WITH ENCRYPTION AS ' 
                          end) 
 
if @type='TR' 
begin 
declare @parent_obj varchar(255),@tr_parent_xtype varchar(10) 
select @parent_obj=parent_obj from sysobjects where id=object_id(@objectName) 
select @tr_parent_xtype=xtype from sysobjects where id=@parent_obj 
if @tr_parent_xtype='V' 
begin 
set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 ' 
end 
else 
begin 
花生采摘机
set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 ' 
end 
 
end 
if @type='FN' or @type='TF' or @type='IF' 
set @sql1=(case @type when 'TF' then 
'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end ' 
when 'FN' then 
'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end' 
when 'IF' then 
'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a' 
end) 
 
if @type='V' 
set @sql1='ALTER VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f' 
 
set @q=len(@sql1) 
set @sql1=@sql1+REPLICATE('-',4000-@q) 
select @sql2=REPLICATE('-',8000) 
set @sql3='exec(@sql1' 
select @colid=max(colid) from #temp where number=@k 
set @n=1 
while @n<=CEILING(1.0*(@colid-1)/2) and len(@sQL3)<=3996 
begin 
set @sql3=@sql3+'+@' 
set @n=@n+1 
end 
set @sql3=@sql3+')' 
exec sp_executesql @sql3,N'@Sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2 
 
end 
曝斯坦福校长学术不端set @k=@k+1 
end 
 
set @k=0 
while @k<=@number 
begin 
 
if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k) 
begin 
select @colid=max(colid) from #temp where number=@k 
set @n=1 
 
while @n<=@colid 
begin 
select @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp  WHERE colid=@n and number=@k 
 
SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=object_id(@objectName) and colid=@n and number=@k) 
if @n=1 
begin 
if @type='P' 
俄罗斯性格
SET @OrigSpText2=(case when @number>1 then 'CREATE PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS ' 
                      else 'CREATE PROCEDURE '+ @objectName +' WITH ENCRYPTION AS ' 
                      end) 
 
 
if @type='FN' or @type='TF' or @type='IF' 
SET @OrigSpText2=(case @type when 'TF' then 
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end ' 
when 'FN' then 
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end' 

本文发布于:2024-09-22 13:35:49,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/100014.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:过程   触发器   视图   字节   受限制   加密   需要   校长
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议