主頁 > 知識(shí)庫 > SQLSERVER對(duì)加密的存儲(chǔ)過程、視圖、觸發(fā)器進(jìn)行解密(推薦)

SQLSERVER對(duì)加密的存儲(chǔ)過程、視圖、觸發(fā)器進(jìn)行解密(推薦)

熱門標(biāo)簽:實(shí)體店地圖標(biāo)注怎么標(biāo) 外呼系統(tǒng)會(huì)封嗎 在電子版地圖標(biāo)注要收費(fèi)嗎 萬利達(dá)綜合醫(yī)院地圖標(biāo)注點(diǎn) 電銷機(jī)器人 深圳 南京電銷外呼系統(tǒng)哪家好 地圖標(biāo)注如何弄全套標(biāo) 武漢AI電銷機(jī)器人 股票配資電銷機(jī)器人

加密測(cè)試的存儲(chǔ)過程

IF EXISTS(SELECT 1 FROM SYSOBJECTS WHERE TYPE='P' AND NAME='P_TEST')
DROP PROCEDURE P_TEST
GO
CREATE PROCEDURE P_TEST(@USERNAME VARCHAR(20),@MSG VARCHAR(20) OUTPUT)
WITH ENCRYPTION
AS
BEGIN
  IF(SELECT COUNT(1) FROM Custs WHERE NAME=@USERNAME)>0
    SET @MSG='此用戶名存在'
  ELSE
    SET @MSG='此用戶名不存在'
END

解密的存儲(chǔ)過程

Create PROCEDURE Decryption(@procedure sysname = NULL)
AS
SET NOCOUNT ON
DECLARE @intProcSpace bigint, @t bigint, @maxColID smallint,@procNameLength int
select @maxColID = max(subobjid) FROM
sys.sysobjvalues WHERE objid = object_id(@procedure)
--select @maxColID as 'Rows in sys.sysobjvalues'
select @procNameLength = datalength(@procedure) + 29
DECLARE @real_01 nvarchar(max)
DECLARE @fake_01 nvarchar(max)
DECLARE @fake_encrypt_01 nvarchar(max)
DECLARE @real_decrypt_01 nvarchar(max),@real_decrypt_01a nvarchar(max)
declare @objtype varchar(2),@ParentName nvarchar(max)
select @real_decrypt_01a = ''
--提取對(duì)象的類型如是存儲(chǔ)過程還是函數(shù),如果是觸發(fā)器,還要得到其父對(duì)象的名稱
select @objtype=type,@parentname=object_name(parent_object_id)
from sys.objects where [object_id]=object_id(@procedure)
-- 從sys.sysobjvalues里提出加密的imageval記錄
SET @real_01=(SELECT top 1 imageval FROM sys.sysobjvalues WHERE objid =
object_id(@procedure) and valclass = 1 order by subobjid)
 
--創(chuàng)建一個(gè)臨時(shí)表
create table #output ( [ident] [int] IDENTITY (1, 1) NOT NULL ,
[real_decrypt] NVARCHAR(MAX) )
--開始一個(gè)事務(wù),稍后回滾
BEGIN TRAN
--更改原始的存儲(chǔ)過程,用短橫線替換
if @objtype='P'
 SET @fake_01='ALTER PROCEDURE '+ @procedure +' WITH ENCRYPTION AS select 1
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/'
else if @objtype='FN'
 SET @fake_01='ALTER FUNCTION '+ @procedure +'() RETURNS INT WITH ENCRYPTION AS BEGIN RETURN 1
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/ END'
else if @objtype='V'
 SET @fake_01='ALTER view '+ @procedure +' WITH ENCRYPTION AS select 1 as col
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/'
else if @objtype='TR'
 SET @fake_01='ALTER trigger '+ @procedure +' ON '+@parentname+'WITH ENCRYPTION AFTER INSERT AS RAISERROR (''N'',16,10)
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/'
EXECUTE (@fake_01)
--從sys.sysobjvalues里提出加密的假的
SET @fake_encrypt_01=(SELECT top 1 imageval FROM sys.sysobjvalues WHERE objid =
object_id(@procedure) and valclass = 1 order by subobjid )
if @objtype='P'
 SET @fake_01='Create PROCEDURE '+ @procedure +' WITH ENCRYPTION AS select 1
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/'
else if @objtype='FN'
 SET @fake_01='CREATE FUNCTION '+ @procedure +'() RETURNS INT WITH ENCRYPTION AS BEGIN RETURN 1
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/ END'
else if @objtype='V'
 SET @fake_01='Create view '+ @procedure +' WITH ENCRYPTION AS select 1 as col
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/'
else if @objtype='TR'
 SET @fake_01='Create trigger '+ @procedure +' ON '+@parentname+'WITH ENCRYPTION AFTER INSERT AS RAISERROR (''N'',16,10)
 /**//*'+REPLICATE(cast('*'as nvarchar(max)), datalength(@real_01) /2 - @procNameLength)+'*/'
--開始計(jì)數(shù)
SET @intProcSpace=1
--使用字符填充臨時(shí)變量
SET @real_decrypt_01 = replicate(cast('A'as nvarchar(max)), (datalength(@real_01) /2 ))
--循環(huán)設(shè)置每一個(gè)變量,創(chuàng)建真正的變量
--每次一個(gè)字節(jié)
SET @intProcSpace=1
--如有必要,遍歷每個(gè)@real_xx變量并解密
WHILE @intProcSpace=(datalength(@real_01)/2)
BEGIN
--真的和假的和加密的假的進(jìn)行異或處理
SET @real_decrypt_01 = stuff(@real_decrypt_01, @intProcSpace, 1,
NCHAR(UNICODE(substring(@real_01, @intProcSpace, 1)) ^
(UNICODE(substring(@fake_01, @intProcSpace, 1)) ^
UNICODE(substring(@fake_encrypt_01, @intProcSpace, 1)))))
SET @intProcSpace=@intProcSpace+1
END
 
 
--通過sp_helptext邏輯向表#output里插入變量
insert #output (real_decrypt) select @real_decrypt_01
--select real_decrypt AS '#output chek' from #output --測(cè)試
-- -------------------------------------
--開始從sp_helptext提取
-- -------------------------------------
declare @dbname sysname
,@BlankSpaceAdded int
,@BasePos int
,@CurrentPos int
,@TextLength int
,@LineId int
,@AddOnLen int
,@LFCR int --回車換行的長(zhǎng)度
,@DefinedLength int
,@SyscomText nvarchar(max)
,@Line nvarchar(255)
Select @DefinedLength = 255
SELECT @BlankSpaceAdded = 0 --跟蹤行結(jié)束的空格。注意Len函數(shù)忽略了多余的空格
CREATE TABLE #CommentText
(LineId int
,Text nvarchar(255) collate database_default)
--使用#output代替sys.sysobjvalues
DECLARE ms_crs_syscom CURSOR LOCAL
FOR SELECT real_decrypt from #output
ORDER BY ident
FOR READ ONLY
--獲取文本
SELECT @LFCR = 2
SELECT @LineId = 1
OPEN ms_crs_syscom
FETCH NEXT FROM ms_crs_syscom into @SyscomText
WHILE @@fetch_status >= 0
BEGIN
SELECT @BasePos = 1
SELECT @CurrentPos = 1
SELECT @TextLength = LEN(@SyscomText)
WHILE @CurrentPos != 0
BEGIN
--通過回車查找行的結(jié)束
SELECT @CurrentPos = CHARINDEX(char(13)+char(10), @SyscomText,
@BasePos)
--如果找到回車
IF @CurrentPos != 0
BEGIN
--如果@Lines的長(zhǎng)度的新值比設(shè)置的大就插入@Lines目前的內(nèi)容并繼續(xù)
While (isnull(LEN(@Line),0) + @BlankSpaceAdded +
@CurrentPos-@BasePos + @LFCR) > @DefinedLength
BEGIN
SELECT @AddOnLen = @DefinedLength-(isnull(LEN(@Line),0) +
@BlankSpaceAdded)
INSERT #CommentText VALUES
( @LineId,
isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText,
@BasePos, @AddOnLen), N''))
SELECT @Line = NULL, @LineId = @LineId + 1,
@BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0
END
SELECT @Line = isnull(@Line, N'') +
isnull(SUBSTRING(@SyscomText, @BasePos, @CurrentPos-@BasePos + @LFCR), N'')
SELECT @BasePos = @CurrentPos+2
INSERT #CommentText VALUES( @LineId, @Line )
SELECT @LineId = @LineId + 1
SELECT @Line = NULL
END
ELSE
--如果回車沒找到
BEGIN
IF @BasePos = @TextLength
BEGIN
--如果@Lines長(zhǎng)度的新值大于定義的長(zhǎng)度
While (isnull(LEN(@Line),0) + @BlankSpaceAdded +
@TextLength-@BasePos+1 ) > @DefinedLength
BEGIN
SELECT @AddOnLen = @DefinedLength -
(isnull(LEN(@Line),0) + @BlankSpaceAdded)
INSERT #CommentText VALUES
( @LineId,
isnull(@Line, N'') + isnull(SUBSTRING(@SyscomText,
@BasePos, @AddOnLen), N''))
SELECT @Line = NULL, @LineId = @LineId + 1,
@BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded =
0
END
SELECT @Line = isnull(@Line, N'') +
isnull(SUBSTRING(@SyscomText, @BasePos, @TextLength-@BasePos+1 ), N'')
if LEN(@Line)  @DefinedLength and charindex(' ',
@SyscomText, @TextLength+1 ) > 0
BEGIN
SELECT @Line = @Line + ' ', @BlankSpaceAdded = 1
END
END
END
END
FETCH NEXT FROM ms_crs_syscom into @SyscomText
END
IF @Line is NOT NULL
INSERT #CommentText VALUES( @LineId, @Line )
select Text from #CommentText order by LineId
CLOSE ms_crs_syscom
DEALLOCATE ms_crs_syscom
DROP TABLE #CommentText
-- -------------------------------------
--結(jié)束從sp_helptext提取
-- -------------------------------------
--刪除用短橫線創(chuàng)建的存儲(chǔ)過程并重建原始的存儲(chǔ)過程
ROLLBACK TRAN
DROP TABLE #output
GO
啟用DAC
SP_CONFIGURE 'remote admin connections';
GO
----0:僅允許本地連接使用 DAC,1:允許遠(yuǎn)程連接使用 DAC
SP_CONFIGURE 'remote admin connections', 0;
GO
RECONFIGURE WITH OVERRIDE;
GO 

文件——>新建——>數(shù)據(jù)庫引擎查詢

服務(wù)器名稱:admin:.或者admin:服務(wù)器名稱

登錄進(jìn)去執(zhí)行解密操作

USE TEST
EXEC Decryption P_TEST
GO

為了安全起見,不要在正式環(huán)境進(jìn)行解密,避免在解密過程中將原存儲(chǔ)過程損壞!

總結(jié)

以上所述是小編給大家介紹的SQLSERVER對(duì)加密的存儲(chǔ)過程、視圖、觸發(fā)器進(jìn)行解密,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

您可能感興趣的文章:
  • 關(guān)于喜憂參半的SQL Server觸發(fā)器詳解
  • 利用SQL Server觸發(fā)器實(shí)現(xiàn)表的歷史修改痕跡記錄
  • SQL Server 使用觸發(fā)器(trigger)發(fā)送電子郵件步驟詳解
  • SQL Server實(shí)現(xiàn)用觸發(fā)器捕獲DML操作的會(huì)話信息【實(shí)例】
  • SQL Server:觸發(fā)器實(shí)例詳解
  • SqlServer觸發(fā)器詳解
  • SqlServer實(shí)現(xiàn)類似Oracle的before觸發(fā)器示例
  • SQL SERVER中各類觸發(fā)器的完整語法及參數(shù)說明
  • SQL SERVER 觸發(fā)器介紹
  • SQL Server誤區(qū)30日談 第4天 DDL觸發(fā)器就是INSTEAD OF觸發(fā)器
  • SQL Server 觸發(fā)器詳情

標(biāo)簽:武威 泰安 汕頭 濟(jì)寧 濟(jì)源 臺(tái)州 安徽 廣東

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQLSERVER對(duì)加密的存儲(chǔ)過程、視圖、觸發(fā)器進(jìn)行解密(推薦)》,本文關(guān)鍵詞  SQLSERVER,對(duì),加密,的,存儲(chǔ),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《SQLSERVER對(duì)加密的存儲(chǔ)過程、視圖、觸發(fā)器進(jìn)行解密(推薦)》相關(guān)的同類信息!
  • 本頁收集關(guān)于SQLSERVER對(duì)加密的存儲(chǔ)過程、視圖、觸發(fā)器進(jìn)行解密(推薦)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章