Any stored procedure or view or function can be encrypted when stored in
the sql server , so a user can not see the code inside even if the user
has SYSADMIN role and it is also not recommended to use this encryption
option to hide the code because once you use the encryption option
Microsoft sql server does not provide the option or the feature to
reverse the setting or decrypt the object , so when you use the
encryption option , save your code in a separate instance![]() ![]() ![]()
TITLE: Microsoft SQL Server Management Studio Script failed for StoredProcedure ‘dbo.test_encrp’. (Microsoft.SqlServer.Smo) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1750.9+((dac_inplace_upgrade).101209-1051+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Script+StoredProcedure&LinkId=20476 —————————— Property TextHeader is not available for StoredProcedure ‘[dbo].[test_encrp]‘. This property may not exist for this object, or may not be retrievable due to insufficient access rights. The text is encrypted. (Microsoft.SqlServer.Smo) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1750.9+((dac_inplace_upgrade).101209-1051+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.PropertyCannotBeRetrievedExceptionText&EvtID=TextHeader&LinkId=20476 First we will see how it looks in the sql_modules catalog views, in the process we will also list all the encrypted stored procedures in the databases to find all the encrypted objects in the sql server database
here is the query used above: select o.name,s.definition,o.type_desc, case from sys.sql_modules s inner join sys.objects o on s.object_id = o.object_id where type in (‘p’,'tr’,'FN’,'tf’,'v’) now we got know how it is encrypted , and where to find the encrypted objects now we will look in to how to decrypt them There are two ways you can do
first we will look at the script method first you need to have SYSADMIN role assigned to you , then you have to setup a DAC connection to the sql server instance that you want to decrypt the objects.
here is the code to decrypt
/****** Object: StoredProcedure [dbo].[sp__procedure] Script Date: 03/06/2012 19:56:01 ******/ SET QUOTED_IDENTIFIER ON CREATE PROCEDURE [dbo].[sp__procedure] DECLARE @intProcSpace bigint, @t bigint, @maxColID smallint,@intEncrypted –select @maxColID as ‘Rows in sys.sysobjvalues’ 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) select @real_decrypt_01a = ” – extract the encrypted imageval rows from sys.sysobjvalues – create this table for later use – We’ll begin the transaction and roll it back later EXECUTE (@fake_01) – extract the encrypted fake imageval rows from sys.sysobjvalues SET @fake_01=’CREATE PROCEDURE ‘+ @procedure +’ WITH ENCRYPTION AS –loop through each of the variables sets of variables, building the real variable – Go through each @real_xx variable and decrypt it, as necessary – Load the variables into #output for handling by sp_helptext logic insert #output (real_decrypt) select @real_decrypt_01 – ————————————- Select @DefinedLength = 255 – use #output instead of sys.sysobjvalues – Else get the text. SELECT @LFCR = 2 OPEN ms_crs_syscom FETCH NEXT FROM ms_crs_syscom into @SyscomText WHILE @@fetch_status >= 0 SELECT @BasePos = 1 WHILE @CurrentPos != 0 –If carriage return found While (isnull(LEN(@Line),0) + @BlankSpaceAdded + FETCH NEXT FROM ms_crs_syscom into @SyscomText IF @Line is NOT NULL select Text from #CommentText order by LineId CLOSE ms_crs_syscom DROP TABLE #CommentText – ————————————- – Drop the procedure that was setup with dashes and rebuild it with the good stuff DROP TABLE #output the second way is to use the third party tools , there many third party tools that are available to download one of the best is the Optillect sql decrypter which is a free ware, good thing about it is it does not need SYSADMIN role as it does not use DAC , rather it uses DBCC ind, and DBCC PAGE for the required information for the SYS.OBJVALUES table http://download.cnet.com/Optillect-SQL-Decryptor/3640-10254_4-75300271-1.html
download and install it
|
手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )
GMT-8, 2026-10-11 20:28 , Processed in 0.006024 second(s), 17 queries .
Supported by BestDeal Online X5.0
© 2001-2026 Discuz! Team.