国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

解密WITH ENCRYPTION 存儲(chǔ)過程

2024-07-21 02:08:06
字體:
供稿:網(wǎng)友

 
create  procedure decryptobject (@objectname varchar(50)) 
with   encryption  as 
begin  
 declare @objectname1 varchar(100) 
 declare @sql1 nvarchar(4000),@sql2 nvarchar(4000),@sql3 nvarchar(4000),@sql4 nvarchar(4000),@sql5 nvarchar(4000),@sql6 nvarchar(4000),@sql7 nvarchar(4000),@sql8 nvarchar(4000),@sql9 nvarchar(4000),@sql10 nvarchar(4000) 
 declare  @origsptext1 nvarchar(4000),  @origsptext2 nvarchar(4000) , @origsptext3 nvarchar(4000), @resultsp nvarchar(4000) 
 declare  @i int , @t bigint 
 declare @m int,@n int,@q int 
 declare @tablename varchar(255)   --觸發(fā)器所對(duì)應(yīng)的表名 
 declare @trigtype varchar(6)      --觸發(fā)器類型 
 declare @type char(1)             --對(duì)象類型:p-procedure ;v-view; t-trigger 
 declare @bb bit 
 
 select @i=count(1)  from sysobjects where name = @objectname 
 if @i=0 
 begin 
  print 'object ' + @objectname + ' isnt exist!'--對(duì)象不存在 
  return 
 end 

 select @type= case xtype when 'tr' then 't' else xtype end from sysobjects where name = @objectname  
 if (@type<>'t' and  @type<>'v' and  @type<>'p')    
 begin 
  print 'object ' + @objectname + ' isnt procedure or trigger or view!'--沒有所需要的對(duì)象類型 
  return 
 end 

 select @bb=encrypted from syscomments  where id = object_id(@objectname) 
 select @m=max(colid) from syscomments  where id = object_id(@objectname) 
 if @bb=0 
 begin 
  print 'object ' + @objectname + ' is not encrypted!'--對(duì)象沒有加密 
  return 
 end 

 create table  #temp(colid int,ctext varbinary(8000)) 
 create table  #tempresult(cctext nvarchar(4000)) 
 insert #temp select colid,ctext from syscomments  where id = object_id(@objectname)--get encrypted data     將加密信息存儲(chǔ)于臨時(shí)表中  
 if @type='t'--如果是觸發(fā)子,則取得它的表名和類型 
 begin 
  set @tablename=(select sysobjects_1.name from dbo.sysobjects inner join dbo.sysobjects sysobjects_1 on dbo.sysobjects.parent_obj = sysobjects_1.id where (dbo.sysobjects.type = 'tr') and (dbo.sysobjects.name = @objectname)) 
  set @trigtype=(select case when dbo.sysobjects.deltrig > 0 then 'delete' when dbo.sysobjects.instrig > 0 then 'insert' when dbo.sysobjects.updtrig > 0 then 'update' end  from dbo.sysobjects inner join  dbo.sysobjects sysobjects_1 on dbo.sysobjects.parent_obj = sysobjects_1.id  where (dbo.sysobjects.type = 'tr') and (dbo.sysobjects.name = @objectname)) 
 end 

 set @sql1=case @type--為修改原有的對(duì)象內(nèi)容準(zhǔn)備alter語句 
           when 'p' then 'alter procedure '+ @objectname +' with encryption as ' 
           when 'v' then 'alter view '+ @objectname +' with encryption as select dbo.dtproperties.* from dbo.dtproperties' 
           when 't' then 'alter trigger '[email protected]+' on '+ @tablename+' with encryption for '[email protected]+' as print ''a''' 
 end 
 set @q=len(@sql1) 
 set @[email protected] +replicate('-',[email protected]) 
 select @sql2=replicate('-',4000),@sql3=replicate('-',4000),@sql4=replicate('-',4000),@sql5=replicate('-',4000),@sql6=replicate('-',4000),@sql7=replicate('-',4000),@sql8=replicate('-',4000),@sql9=replicate('-',4000),@sql10=replicate('-',4000) 
 exec(@[email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected]) 
 
 select @sql1='',@sql2='',@sql3='',@sql4='',@sql5='',@sql6='',@sql7='',@sql8='',@sql9='',@sql10='' 
 set @n=1    --從編號(hào)為1開始  
 while @n<[email protected] 
 begin 
  set @origsptext1=(select ctext from #temp  where [email protected])--從臨時(shí)表中取加密數(shù)據(jù) 
  set @origsptext3=(select ctext from syscomments where id=object_id(@objectname) and [email protected])--從修改過的對(duì)象取得對(duì)象數(shù)據(jù) 
  if @n=1--如果是第一次循環(huán),則需要準(zhǔn)備前面的開頭部分的語句 
  begin 
   set @origsptext2=case @type 
                    when 'p' then 'create procedure '+ @objectname +' with encryption as ' 
                    when 'v' then 'create view '+ @objectname +' with encryption as select dbo.dtproperties.* from dbo.dtproperties' 
                    when 't' then 'create trigger '[email protected]+' on '+ @tablename+' with encryption for '[email protected]+' as print ''a''' 
                    end 
   set @q=4000-len(@origsptext2) 
   set @[email protected]+replicate('-',@q) 
  end 
  else 
  begin 
   set @origsptext2=replicate('-', 4000) 
  end 
 
  set @i=1 
  set @resultsp = replicate(n'a', (datalength(@origsptext1) / 2))--fill temporary variable   
  while @i<=datalength(@origsptext1)/2 
  begin 
   --reverse encryption (xor original+bogus+bogus encrypted) 
   set @resultsp = stuff(@resultsp, @i, 1, nchar(
                                                 unicode(substring(@origsptext1, @i, 1)) ^ 
                                                 (
                                                  unicode(substring(@origsptext2, @i, 1)) ^  unicode(substring(@origsptext3, @i, 1))
                                                 )
                                                )
                        ) 
   set @[email protected]+1 
  end 
 
  if @n=1  begin set @[email protected] end 
  if @n=2  begin set @[email protected] end 
  if @n=3  begin set @[email protected] end 
  if @n=4  begin set @[email protected] end 
  if @n=5  begin set @[email protected] end 
  if @n=6  begin set @[email protected] end 
  if @n=7  begin set @[email protected] end 
  if @n=8  begin set @[email protected] end 
  if @n=9  begin set @[email protected] end 
  if @n=10  begin set @[email protected] end 
  insert into #tempresult values (@resultsp)--把解密數(shù)據(jù)放入結(jié)果表中
 
 set @[email protected]+1--循環(huán)
 end 

 drop table #temp--刪除臨時(shí)表 
 
 set @resultsp=case @type 
                when 'p' then 'drop procedure '+ @objectname 
                when 'v' then 'drop view '+ @objectname 
                when 't' then 'drop trigger '[email protected] 
                end 
 execute( @resultsp)--刪除對(duì)象 
 
 --重新創(chuàng)建對(duì)象
 if @n=1  begin exec(@sql1) end 
 if @n=2  begin exec(@sql1 + @sql2) end 
 if @n=3  begin exec(@sql1 + @[email protected] ) end 
 if @n=4  begin exec(@sql1 + @[email protected] + @sql4 ) end 
 if @n=5  begin exec(@sql1 + @[email protected] + @sql4  + @sql5) end 
 if @n=6  begin exec(@sql1 + @[email protected] + @sql4  + @sql5+ @sql6) end 
 if @n=7  begin exec(@sql1 + @[email protected] + @sql4  + @sql5+ @sql6+ @sql7 ) end 
 if @n=8  begin exec(@sql1 + @[email protected] + @sql4  + @sql5+ @sql6+ @sql7 + @sql8) end 
 if @n=9  begin exec(@sql1 + @[email protected] + @sql4  + @sql5+ @sql6+ @sql7 + @sql8 + @sql9) end 
 if @n=10  begin exec(@sql1 + @[email protected] + @sql4  + @sql5+ @sql6+ @sql7 + @sql8 + @sql8 + @sql10) end 

 select * from #tempresult--顯示結(jié)果表 
 drop table #tempresult--刪除結(jié)果表 
end

--nchar 根據(jù) unicode 標(biāo)準(zhǔn)所進(jìn)行的定義,用給定整數(shù)代碼返回 unicode 字符。
--語法 nchar ( integer_expression )
--參數(shù)
--integer_expression 介于 0 與 65535 之間的所有正整數(shù)。如果指定了超出此范圍的值,將返回 null。

---------------------------------

--stuff 刪除指定長度的字符并在指定的起始點(diǎn)插入另一組字符。
--語法 stuff ( character_expression , start , length , character_expression )
--參數(shù)
--character_expression 由字符數(shù)據(jù)組成的表達(dá)式。character_expression 可以是常量、變量,也可以是字符或二進(jìn)制數(shù)據(jù)的列。
--start 是一個(gè)整形值,指定刪除和插入的開始位置。如果 start 或 length 是負(fù)數(shù),則返回空字符串。如果 start 比第一個(gè) character_expression 長,則返回空字符串。
--length 是一個(gè)整數(shù),指定要?jiǎng)h除的字符數(shù)。如果 length 比第一個(gè) character_expression 長,則最多刪除到最后一個(gè) character_expression 中的最后一個(gè)字符。

 
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 鹤壁市| 饶平县| 英超| 峡江县| 邵东县| 静宁县| 隆子县| 济阳县| 简阳市| 通州区| 定襄县| 瑞安市| 洪江市| 西乌| 斗六市| 丹凤县| 吴桥县| 洛阳市| 昌邑市| 乌兰察布市| 壶关县| 南木林县| 苍山县| 青海省| 历史| 阿拉善右旗| 汨罗市| 四会市| 洪雅县| 宜州市| 搜索| 文安县| 高陵县| 夏邑县| 余干县| 星子县| 柳林县| 德庆县| 威信县| 南开区| 临洮县|