Wednesday, February 17, 2010

How to Encrypt a stored procedure/function

1. Create a dummy procedure:

create or replace procedure test

as

begin

dbms_output.put_line( 'Hello world' );

end;

/

Save the above procedure code in test.sql on /bin directory of ORACLE home.

----------------------

2. Check the text from dictionary table:

select text from user_source where name= 'TEST';

It will show the procedure code or contents as created in step 1.

3. To encrypt the procedure contents there is a utility named 'wrap' in ORACLE installation home/bin:

Syntax: wrap iname= <source file name> oname= <output file name>

Login with oracle inventory user (usually oracle) and go to /bin directory of oracle home, then run:

wrap iname=test.sql oname=test_wrap.sql

The above command will create test_wrap.sql which will be having contents of test.sql in encrypted form. Run this script (test_wrap.sql) on sqlplus:

SQL> @test_wrap.sql

This will create the procedure in database but keep the code or contents encrypted into the dictionary table. Now, check the text from dictionary table again:

select text from user_source where name= 'TEST';

Now, it will show the procedure code or contents like:

procedure wrapped
0
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
3
7
8106000
1
4
0
4
2 :e:
1P:

4. MOST IMPORTANT:

Please save the original procedure test.sql somewhere as this is the readable (unencrypted) form of the procedure. The script test_warp.sql and the created procedure into the database are encrypted codes.

No comments:

Post a Comment