How to encrypt all existing stored procedures of a database

前端 未结 8 1947
后悔当初
后悔当初 2021-02-10 10:13

Is there any possibility to encrypt all existing stored procedures of a SQL Server 2008 database AFTER they have been created via an SQLCMD script?

The reason I want to

8条回答
  •  误落风尘
    2021-02-10 10:44

    WITH ENCRYPTION means that the code behind the proc is not stored in the SysComments table.

    You could write a script that does a exec sp_helptext 'MyProcName' and gets the contents into a VarChar (MAX) so it can hold multiline / large procedures easily and then modifiy the procedure from it's original state

    CREATE MyProcName AS
    
    SELECT SecretColumns From TopSecretTable
    

    change CREATE to ALTER and AS surrounded by space or tab or newline (good place to use Regular Expressions) to WITH ENCRYPTION AS

    ALTER MyProcName WITH ENCRYPTION AS
    
    SELECT SecretColumns From TopSecretTable
    

    This will hide all code for the stored proc on the production server.

    You can put this in a LOOP or a CURSOR (not really a set based operation IMHO) for all objects of a specific type and/or naming convention that you want to encrypt, and run it every time you deploy.

提交回复
热议问题