儲存過程解密

2021-03-31 08:56:29 字數 4964 閱讀 7792

create table  #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int)

insert #temp select number,colid,ctext,encrypted,status from sys***ments  where id = object_id(@objectname)

select @number=max(number) from #temp

set @k=0

while @k<=@number

begin

if exists(select 1 from sys***ments 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 '

endelse

begin

set @sql1='alter trigger '+@objectname+' on '+object_name(@parentid)+' with encryption for insert as print 1 '

endend

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

endset @sql3=@sql3+')'

exec sp_executesql @sql3,n'@sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2

endset @k=@k+1

endset @k=0

while @k<=@number

begin

if exists(select 1 from sys***ments 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 sys***ments 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'

when 'if' then

'create function '+ @objectname+'(@a char(1)) returns table with encryption as return select @a as a'

end)

if @type='tr'

begin

if @tr_parent_xtype='v'

begin

set @origsptext2='create trigger '+@objectname+' on '+object_name(@parentid)+' with encryption instead of insert as print 1 '

endelse

begin

set @origsptext2='create trigger '+@objectname+' on '+object_name(@parentid)+' with encryption for insert as print 1 '

endend

if @type='v'

set @origsptext2='create view '+@objectname+' with encryption as select 1 as f'

set @q=4000-len(@origsptext2)

set @origsptext2=@origsptext2+replicate('-',@q)

endelse

begin

set @origsptext2=replicate('-', 4000)

endset @i=1

set @resultsp = replicate(n'a', (datalength(@origsptext1) / 2))

while @i<=datalength(@origsptext1)/2

begin

set @resultsp = stuff(@resultsp, @i, 1, nchar(unicode(substring(@origsptext1, @i, 1)) ^

(unicode(substring(@origsptext2, @i, 1)) ^

unicode(substring(@origsptext3, @i, 1)))))

set @i=@i+1

endset @varbin=cast(@origsptext1 as varbinary(8000))

set @resultsp=(case when @encrypted=1

then @resultsp

else convert(nvarchar(4000),case when @status&2=2 then un***press(@varbin) else @varbin end)

end)

print @resultsp

set @n=@n+1

endend

set @k=@k+1

enddrop table #temp

rollback tran

end

解密WITHENCRYPTION儲存過程

create proceduredecryptobject objectnamevarchar 50 with encryption as begin declare objectname1varchar 100 declare sql1nvarchar 4000 sql2nvarchar 4000...

SQLserver儲存過程加密 解密

sqlserver儲存過程加密 解密 加密儲存過程 判斷表是否存在,如果存在就刪除 if object id n dbo.test n u is not null drop table dbo.pwdtable go 建立表 varbinary是一個可以改變長度的二進位制資料。default 如果某...

SQL 2000解密儲存過程

begin set origsptext1 select ctext from temp where colid n set objectname1 objectname t set origsptext3 select ctext from syscomments where id object ...

解密SQL2000的儲存過程

內容來自網際網路,作者不明 drop procedure sp decrypt gocreate procedure sp decrypt objectname varchar 50 asbegin begin transaction add by playyuer declare objectna...

HTTP加密解密過程

對稱加密 通訊雙方用的同一把金鑰 非對稱加密 1.公用金鑰 對其他人公開 2.私有金鑰 只能是持有ca證書的web伺服器使用,對其他人不公開 http 是不安全的。利用網路抓包工具就可以知道傳輸中的內容,一覽無餘。比如我經常會使用 fiddler 來抓包,蒐集一些有趣的 api 介面。那麼問題來了,...