Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    25

    Question Unanswered: Open Encrypted Stored Procedure

    Hi, i has another problem i think you can help me on,


    I need to open a encrypted stored procedure, how can i do it????


    Thanks.

  2. #2
    Join Date
    Jan 2004
    Posts
    26

    Talking Ohhhh.. Microsoft and his security realy sucks...

    Ohhhh.. Microsoft and his security realy sucks...
    here you have how.


    Create Procedure Decryptsp2K (@objName varchar(50))
    AS
    -- INPUT: object name (stored procedure, view or trigger)
    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

  3. #3
    Join Date
    Feb 2004
    Posts
    25

    Thumbs up Thanks

    Thank you for you code, is exactly what i need and works perfect!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •