资源描述:
《sql存储过程的加密和解密方法(含sql2000和sql2005版本》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、sql存储过程的加密和解密(有sql2000和sql2005)★加密存储过程:IFEXISTS(SELECTnameFROMsysobjectsWHEREname='encrypt_this'ANDtype='P')DROPPROCEDUREencrypt_thisGOUSEpubsGOCREATEPROCEDUREencrypt_thisWITHENCRYPTION---只需要在创建时加入WITHENCRYPTION即可ASSELECT*FROMauthorsGO--查看存储过程文本:EXECsp_help
2、textencrypt_this下面是结果集:Theobject'scommentshavebeenencrypted.----对象已经被加密★解密存储过程:CREATEPROCEDUREsp_decrypt(@objectNamevarchar(50))ASbeginsetnocounton--CSDN:j9988copyright:2004.04.15--V3.1--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器--修正上一版视图触发器不能正确解密错误--发现有错,请E_M
3、AIL:CSDNj9988@tom.combegintrandeclare@objectname1varchar(100),@orgvarbinvarbinary(8000)declare@sql1nvarchar(4000),@sql2varchar(8000),@sql3nvarchar(4000),@sql4nvarchar(4000)DECLARE@OrigSpText1nvarchar(4000),@OrigSpText2nvarchar(4000),@OrigSpText3nvarchar(400
4、0),@resultspnvarchar(4000)declare@iint,@statusint,@typevarchar(10),@parentidintdeclare@colidint,@nint,@qint,@jint,@kint,@encryptedint,@numberintselect@type=xtype,@parentid=parent_objfromsysobjectswhereid=object_id(@ObjectName)createtable#temp(numberint,coli
5、dint,ctextvarbinary(8000),encryptedint,statusint)insert#tempSELECTnumber,colid,ctext,encrypted,statusFROMsyscommentsWHEREid=object_id(@objectName)select@number=max(number)from#tempset@k=0while@k<=@numberbeginifexists(select1fromsyscommentswhereid=object_id(
6、@objectname)andnumber=@k)beginif@type='P'set@sql1=(casewhen@number>1then'ALTERPROCEDURE'+@objectName+';'+rtrim(@k)+'WITHENCRYPTIONAS'else'ALTERPROCEDURE'+@objectName+'WITHENCRYPTIONAS'end)if@type='TR'begindeclare@parent_objvarchar(255),@tr_parent_xtypevarch
7、ar(10)select@parent_obj=parent_objfromsysobjectswhereid=object_id(@objectName)select@tr_parent_xtype=xtypefromsysobjectswhereid=@parent_objif@tr_parent_xtype='V'beginset@sql1='ALTERTRIGGER'+@objectname+'ON'+OBJECT_NAME(@parentid)+'WITHENCRYPTIONINSTERDOFINS
8、ERTASPRINT1'endelsebeginset@sql1='ALTERTRIGGER'+@objectname+'ON'+OBJECT_NAME(@parentid)+'WITHENCRYPTIONFORINSERTASPRINT1'endendif@type='FN'or@type='TF'or@type='IF'set@sql1=(case@typewhen'TF'then'ALTERF