all groups > sql server programming > september 2006 >
You're in the

sql server programming

group:

Create Procedure with Encryption


Create Procedure with Encryption Jami
9/20/2006 11:49:34 PM
sql server programming:
Hi to All!

I have created a stored procedure with Encryption option.
now i wants to modify that procedure but with SP_Helptext command it is
not showing me its contents. how can i decrypt the stored procedure to
modify it.

Regards,
Jami.



Re: Create Procedure with Encryption Uri Dimant
9/21/2006 12:00:00 AM
Jami
googling a little bit

create procedure hello
with encryption
as
print 'hello world'

sp_helptext hello
exec DECRYPTSP2K 'hello'






SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE DECRYPTSP2K (@objName varchar(50))
--INPUT: object name (stored procedure,
--
-- view or trigger)
--Original idea: shoeboy <shoeboy@a
-- dequacy.org>
--Copyright © 1999-2002 SecurityFocus
--adapted by Joseph Gama
--Planet Source Code, my employer and my
--
-- self are not responsible for the use
-- of
-- this code
--This code is provided as is and for ed
--
-- ucational purposes only
--Please test it and share your results
AS
DECLARE @a nvarchar(4000), @b nvarchar(4000), @c nvarchar(4000), @d
nvarchar(4000), @i int, @t bigint
--get encrypted data
SET @a=(SELECT ctext FROM syscomments WHERE id = object_id(@objName))
SET @b='ALTER PROCEDURE '+ @objName +' WITH ENCRYPTION AS '+REPLICATE('-',
4000-62)
EXECUTE (@b)
--get encrypted bogus SP
SET @c=(SELECT ctext FROM syscomments WHERE id = object_id(@objName))
SET @b='CREATE PROCEDURE '+ @objName +' WITH ENCRYPTION AS '+REPLICATE('-',
4000-62)
--start counter
SET @i=1
--fill temporary variable
SET @d = replicate(N'A', (datalength(@a) / 2))
--loop
WHILE @i<=datalength(@a)/2
BEGIN
--xor original+bogus+bogus encrypted
SET @d = stuff(@d, @i, 1,
NCHAR(UNICODE(substring(@a, @i, 1)) ^
(UNICODE(substring(@b, @i, 1)) ^
UNICODE(substring(@c, @i, 1)))))
SET @i=@i+1
END
--drop original SP
EXECUTE ('drop PROCEDURE '+ @objName)
--remove encryption
--try to preserve case
SET @d=REPLACE((@d),'WITH ENCRYPTION', '')
SET @d=REPLACE((@d),'With Encryption', '')
SET @d=REPLACE((@d),'with encryption', '')
IF CHARINDEX('WITH ENCRYPTION',UPPER(@d) )>0
SET @d=REPLACE(UPPER(@d),'WITH ENCRYPTION', '')
--replace SP
execute( @d)

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


[quoted text, click to view]

AddThis Social Bookmark Button