oracle提供了一个叫wrap的操作系统命令行工具,用来加密存储过程、函数、包等PL/SQL源代码。防止其他用户对商业逻辑的偷窥,帮助保守商业密码。
语法
wrap iname=input_file [oname=output_file]
input_file为输入文件的名字,该文件含有源代码,output_file为输出文件的名字,oname可选,如果不带oname选项,则生成名字跟输入文件相同,文件后缀为.plb。
示例:
在/home/oracle目录下创建存储过程源文件pro_source.sql,内容为如下:
create or replace procedure hbk_secret is
begin
dbms_output.put_line('I Love you,zhanglulu,My wife');
end;
使用wrap命令生成加密,加密后的文件为pro_pwd.sql
[root@test11g oracle]# pwd
/home/oracle
[root@test11g oracle]# ll |grep pro_source.sql
-rw-r--r-- 1 root root 108 7月 10 17:08 pro_source.sql
[root@test11g oracle]# cat pro_source.sql
create or replace procedure hbk_secret is
begin
dbms_output.put_line('I Love you,zhanglulu,My wife');
end;
[root@test11g oracle]# wrap iname=/home/oracle/pro_source.sql oname=/home/oracle/pro_pwd.sql
PL/SQL Wrapper: Release 11.2.0.1.0- 64bit Production on Wed Jul 10 17:09:47 2019
Copyright (c) 1993, 2009, Oracle. All rights reserved.
Processing /home/oracle/pro_source.sql to /home/oracle/pro_pwd.sql
执行加密后的存储过程文件,将创建相对应的存储过程。
[oracle@test11g ~]$ sqlplus hbk/hbk
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 10 17:10:23 2019
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> @ /home/oracle/pro_pwd.sql
Procedure created.
执行存储过程
SQL> set serveroutput on;
SQL> execute hbk_secret;
I Love you,zhanglulu,My wife
PL/SQL procedure successfully completed.
查看存储过程的源代码:
SQL > select name,text from all_source where type='PROCEDURE' and name='HBK_SECRET';
查看的结果跟直接使用操作系统命令查看相同,已经加密了。
[root@test11g oracle]# cat pro_pwd.sql
create or replace procedure hbk_secret wrapped
a000000
1
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
7
5b 9e
Iglb06MHVSiBupA9nP6gE08Pj34wg5nnm7+fMr2ywFyFWpdKltwu0fJizKV0i8DAMv7Shgb1
UpuySv4osr3nsrMdBjAsriTqsjKuRE/kwsMCl+QJkOVf2zTSbiVuCaSa8gKbR6DDMi720eok
H/bROaY2dP0C
/