大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 数据库 -> 查看SQL SERVER 加密存储过程,函数,触发器,视图

查看SQL SERVER 加密存储过程,函数,触发器,视图

时间: 2021-07-31 作者:daque

createprocedure sp_decrypt(@objectname varchar(50))asbeginset nocount on--csdn:j9988 copyright:2004.07.15 --v3.2 --破译字节不受控制,实用于sqlserver2000保存进程,函数,视图,触发器--矫正上一版"视图触发器"不许精确解密缺点--创造有错,请e_mail:csdnj9988@tom.combegin trandeclare @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 intdeclare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number intselect @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 syscommentswhere id = object_id(@objectname)select @number=max(number) from #tempset @k=0while @k<=@number beginif exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)beginif @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'begindeclare @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_objif @tr_parent_xtype='v'beginset @sql1='alter trigger '+@objectname+' on '+object_name(@parentid)+' with encryption insterd of insert as print 1 'endelsebeginset @sql1='alter trigger '+@objectname+' on '+object_name(@parentid)+' with encryption for insert as print 1 'endendif @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=1while @n<=ceiling(1.0*(@colid-1)/2) and len(@sql3)<=3996begin set @sql3=@sql3+'+@'set @n=@n+1endset @sql3=@sql3+')'exec sp_executesql @sql3,n'@sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2endset @k=@k+1endset @k=0while @k<=@number beginif exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)beginselect @colid=max(colid) from #temp where number=@k set @n=1while @n<=@colidbeginselect @origsptext1=ctext,@encrypted=encrypted,@status=status from #tempwhere colid=@n and number=@kset @origsptext3=(select ctext from syscomments where id=object_id(@objectname) and colid=@n and number=@k)if @n=1beginif @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'when 'if' then'create function '+ @objectname+'(@a char(1)) returns table with encryption as return select @a as a'end)if @type='tr' beginif @tr_parent_xtype='v'beginset @origsptext2='create trigger '+@objectname+' on '+object_name(@parentid)+' with encryption instead of insert as print 1 'endelsebeginset @origsptext2='create trigger '+@objectname+' on '+object_name(@parentid)+' with encryption for insert as print 1 'endendif @type='v'set @origsptext2='create view '+@objectname+' with encryption as select 1 as f'set @q=4000-len(@origsptext2)set @origsptext2=@origsptext2+replicate('-',@q)endelsebeginset @origsptext2=replicate('-', 4000)endset @i=1set @resultsp = replicate(n'a', (datalength(@origsptext1) / 2))while @i<=datalength(@origsptext1)/2beginset @resultsp = stuff(@resultsp, @i, 1, nchar(unicode(substring(@origsptext1, @i, 1)) ^(unicode(substring(@origsptext2, @i, 1)) ^unicode(substring(@origsptext3, @i, 1))))) set @i=@i+1endset @orgvarbin=cast(@origsptext1 as varbinary(8000))set @resultsp=(case when @encrypted=1 then @resultsp else convert(nvarchar(4000),case when @status&2=2 then uncompress(@orgvarbin) else @orgvarbin end) end)print @resultspset @n=@n+1endendset @k=@k+1enddrop table #temprollback tranend

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.