欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle PL/SQL代码加解密

程序员文章站 2022-06-08 08:48:31
...

Oracle 10g PL/SQL的wrap过程是对源码先进行lz压缩lzstr,然后对压缩数据进行SHA-1运算得到40位的加密串shstr,然后将加密串与压

通过Oracle的PL/SQL代码加密来保护业务逻辑在有些场合非常有用,,简单整理了下:

一. 通过Wrap命令来加密

1. 创建一个例子文件pro_wrap.sql

create or replace procedure pro_wrap is
begin
dbms_output.put_line('Wrap Demo');
end pro_wrap;

2. 通过wrap命令来生成pld加密文件

wrap iname=c:\pk\pro_wrap.sql oname=c:\pk\pro_wrap.plb

c:\pk>wrap iname=c:\pk\pro_wrap.sql oname=c:\pk\pro_wrap.plb

PL/SQL Wrapper: Release 11.2.0.1.0- 64bit Production on 星期二 3月 25 21:58:20 2014

Copyright (c) 1993, 2009, Oracle. All rights reserved.

Processing c:\pk\pro_wrap.sql to c:\pk\pro_wrap.plb

3.通过加密出来的文件pro_wrap.pld,生成存储过程

c:\pk>sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期二 3月 25 22:17:19 2014

Copyright (c) 1982, 2010, Oracle. All rights reserved.


连接到:
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> set serveroutput on
SQL> @c:\pk\pro_wrap.plb

过程已创建。

SQL> exec pro_wrap;
Wrap Demo

PL/SQL 过程已成功完成。

通过exec测试,可看到存储过程执行成功。

4. 再验证下代码是否是加密了的.

SQL> set newpage none
SQL> set heading off
SQL> set space 0
SQL> set pagesize 0
SQL> set trimout on
SQL> set trimspool on
SQL> set linesize 2500
SQL> SELECT dbms_metadata.get_ddl('PROCEDURE','PRO_WRAP') FROM dual;

CREATE OR REPLACE PROCEDURE "SYS"."PRO_WRAP" wrapped
a000000
354
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
7
50 8d
cKb3/QEp0AIWOH/IyhxS2ffLbrUwg5nnm7+fMr2ywFwWFpfQlpbyVmmldIvAwDL+0oYJaWm4
UpuySv4osr3nsrMdBjAsriTqsoG4yGWcd2jPMi720eokHwKpyrXOpcrGpvY5pg2Gb0c=

可知确实是加密了的乱码。

Oracle PL/SQL代码加解密