Results 1 to 4 of 4

Thread: With Encryption

  1. #1
    Join Date
    Sep 2003
    Posts
    69

    Unanswered: With Encryption

    What type of encryption is used on stored procedures and triggers when you specify "WITH ENCRYPTION" when you're creating one? Also is there a way to decrypt them? I (obviously) need to decrypt one I didn't write.

    Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The encryption used is not very good, and I have seen decryption algorythms and procedures on the internet. I'll see whether I have any documentation on this when I go home tonight.

    blindman

  3. #3
    Join Date
    Sep 2003
    Posts
    69
    Actually with some more searching i've found that:

    SQL Sever 7 and 2000 both use a similar method for encryption and that SQL Server 7 is REALLY insecure when it comes to WITH ENCRYPTION...

    anything else would be appreciated. Thanks

  4. #4
    Join Date
    Oct 2003
    Posts
    1

    Decryption SProc

    This sproc will decrypt sprocs encrypted using the "WITH ENCRYPTION" Method. It does not do a 100% decryption, but it will give you the general gist of the sproc.

    Code:
    create  PROCEDURE sp_decrypt_sp (@objectName varchar(50))
    AS
    DECLARE  @OrigSpText1 nvarchar(4000)
    DECLARE  @OrigSpText2 nvarchar(4000)
    DECLARE  @OrigSpText3 nvarchar(4000)
    DECLARE  @resultsp nvarchar(4000)
    declare  @i int , @t bigint
    
    --get encrypted data
    SET @OrigSpText1=(SELECT ctext FROM syscomments  WHERE id = object_id(@objectName))
    SET @OrigSpText2='ALTER PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '+REPLICATE('-', 3938)
    EXECUTE (@OrigSpText2)
    
    SET @OrigSpText3=(SELECT ctext FROM syscomments  WHERE id = object_id(@objectName))
    SET @OrigSpText2='CREATE PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '+REPLICATE('-', 4000-62)
    
    --start counter
    SET @i=1
    --fill temporary variable
    SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2))
    
    --loop
    WHILE @i<=datalength(@OrigSpText1)/2
    BEGIN
    --reverse encryption (XOR original+bogus+bogus encrypted)
    SET @resultsp = stuff(@resultsp, @i, 1, NCHAR(UNICODE(substring(@OrigSpText1, @i, 1)) ^
                                    (UNICODE(substring(@OrigSpText2, @i, 1)) ^
                                    UNICODE(substring(@OrigSpText3, @i, 1)))))
     SET @i=@i+1
    END
    --drop original SP
    EXECUTE ('drop PROCEDURE '+ @objectName)
    --remove encryption
    --preserve case
    SET @resultsp=REPLACE((@resultsp),'WITH ENCRYPTION', '')
    SET @resultsp=REPLACE((@resultsp),'With Encryption', '')
    SET @resultsp=REPLACE((@resultsp),'with encryption', '')
    IF CHARINDEX('WITH ENCRYPTION',UPPER(@resultsp) )>0 
      SET @resultsp=REPLACE(UPPER(@resultsp),'WITH ENCRYPTION', '')
    --replace Stored procedure without enryption
    execute( @resultsp)
    GO

Posting Permissions

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