Oracle wrap 和 unwrap( 加密与解密) 说明
一. Wrap 说明
官网的说明如下:
A PL/SQL Source Text Wrapping
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/wrap.htm#LNPLS1744
You can wrap the PL/SQL source text for any of these stored PL/SQL units, thereby preventing anyone from displaying or editing that text:
(1)Package specification
(2)Package body
(3)Type specification
(4)Type body
(5)Function
(6)Procedure
A file containing wrapped PL/SQL source text is called a wrapped file. Awrapped file can be moved, backed up, or processed by SQL*Plus or the Importand Export utilities.
To produce a wrapped file, use either the PL/SQL Wrapper utility or a DBMS_DDL subprogram.The PL/SQL Wrapper utility wraps the source text of every wrappable PL/SQL unitcreated by a specified SQL file. The DBMS_DDL subprograms wrap thesource text of single dynamically generated wrappable PL/SQL units.
Both the PL/SQL Wrapper utility and DBMS_DDL subprograms detecttokenization errors (for example, runaway strings), but not syntax or semanticerrors (for example, nonexistent tables or views).
Wrapped files are upward-compatible between Oracle Database releases. For example, youcan load files produced by the V8.1.5 PL/SQL Wrapper utility into a V8.1.6 OracleDatabase.
itpub上有篇文章提到了wrap 加密的原理:
From:http://space.itpub.net/12932950/viewspace-619808
Oracle加密的原理就是先对源码进行lz压缩lzstr,然后对压缩数据进行SHA-1运算得到40位的加密串shstr,然后将加密串与压缩串拼接 得到shstr+lzstr,然后对拼接后的字符串进行Oracle双字符转换(转换表)。最后将转换后的字符串进行base64编码,最终得到wrap 的加密串。
The default file extension for input_file is sql. The default nameof output_file is input_file.plb. Therefore, these commands are equivalent:
wrapiname=/mydir/myfile
wrapiname=/mydir/myfile.sql oname=/mydir/myfile.plb
Thisexample specifies a different file extension for input_file and adifferent name for output_file:
wrapiname=/mydir/myfile.src oname=/yourdir/yourfile.out
wrap 的使用步骤如下:
(1)将我们要加密的sql 语句保存到一个sql文本里。
(2)用wrap 进行处理,指定输入的sql,即我们第一步的问题,然后指定输出的路径和文件名,默认扩展名是plb。
(3)执行我们第二部进过wrap 处理的sql,即plb文件,创建我们的对象.
示例1:wrap funcation
--函数
CREATE OR REPLACE FUNCTION F_DAVE (
n int
) RETURN string
IS
BEGIN
IF n = 1 THEN
RETURN 'Dave is DBA!';
ELSIF n = 2 THEN
RETURN 'Dave come from AnQing!';
ELSE
RETURN 'Dave come from HuaiNing!';
END IF;
END;
/
SYS@dave2(db2)> select F_DAVE(4) fromdual;
F_DAVE(4)
--------------------------------------------------------------------------------
Dave come from HuaiNing!
BTW: 今天群里有人问我的blog的例子里为啥有安庆,因为我是安庆怀宁人。
[oracle@db2 ~]$ pwd
/home/oracle
[oracle@db2 ~]$ cat dave.sql
CREATE OR REPLACE FUNCTION F_DAVE (
n int
) RETURNstring
IS
BEGIN
IF n = 1 THEN
RETURN 'Dave is DBA!';
ELSIF n = 2 THEN
RETURN 'Dave come from AnQing!';
ELSE
RETURN 'Dave come from HuaiNing!';
END IF;
END;
/
[oracle@db2 ~]$ wrap iname=dave.sql
PL/SQL Wrapper: Release 10.2.0.1.0-Production on Thu Aug 18 22:59:14 2011
Copyright (c) 1993, 2004, Oracle. All rights reserved.
Processing dave.sql to dave.plb
[oracle@db2 ~]$ ls
bifile.bbd dave.plb dave.sql Desktop log.bbd
[oracle@db2 ~]$ cat dave.plb
CREATE OR REPLACE FUNCTION F_DAVE wrapped
a000000
1
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
10d e7
S9NWrpt8q6tkKEMxCcfYJz2aLF4wgxDQLZ4VfC9AkE6OnV4ydypXGhveHcDg8UXy98WIg6xR
crtc/BRdQJjutbna/9+g0LlaSx87/znV+y926S1AeC0IRi/tjPJTyvJereDdk8mftMo8QMjV
fw0xXn0zVagAawwNVhSAiy/JPTMKkrBkC5ruMwQSTe6JQNq7Q2QtJV0hgQou0rYuet4/gJ5B
wAj75ph6EA==
/
SYS@dave2(db2)> @dave.plb
--再次调用函数,正常使用:
SYS@dave2(db2)> select F_DAVE(4) fromdual;
F_DAVE(4)
--------------------------------------------------------------------------------
Dave come from HuaiNing!
--查看函数源码,已经加过密了:
SYS@dave2(db2)> select text fromdba_source where name='F_DAVE';
TEXT
--------------------------------------------------------------------------------
FUNCTION F_DAVE wrapped
a000000
1
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
TEXT
--------------------------------------------------------------------------------
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
10d e7
S9NWrpt8q6tkKEMxCcfYJz2aLF4wgxDQLZ4VfC9AkE6OnV4ydypXGhveHcDg8UXy98WIg6xR
crtc/BRdQJjutbna/9+g0LlaSx87/znV+y926S1AeC0IRi/tjPJTyvJereDdk8mftMo8QMjV
TEXT
--------------------------------------------------------------------------------
fw0xXn0zVagAawwNVhSAiy/JPTMKkrBkC5ruMwQSTe6JQNq7Q2QtJV0hgQou0rYuet4/gJ5B
wAj75ph6EA==
示例2:SYS.DBMS_DDL 函数
the dbms_ddl package provides wrap functionsand create_wrapped procedures, each of whichwraps the pl/sql source text of a single dynamically generated wrappable pl/sqlunit.
The DBMS_DDL packagealso provides the exception MALFORMED_WRAP_INPUT (ORA-24230),which is raised if the input to WRAP or CREATE_WRAPPED isnot a valid wrappable PL/SQL unit. (For the list of wrappable PL/SQL units, seethe introduction to "PL/SQLSource Text Wrapping".)
Each WRAP functiontakes as input a single CREATE statement that creates a wrappablePL/SQL unit and returns an equivalent CREATE statement in which thePL/SQL source text is wrapped. For more information about the WRAP functions,see OracleDatabase PL/SQL Packages and Types Reference.
Each CREATE_WRAPPED proceduredoes what its corresponding WRAP function does and then runs thereturned CREATE statement, creating the specified PL/SQL unit. Formore information about the CREATE_WRAPPED procedures。
该示例直接参考官方文档:
DECLARE
package_text VARCHAR2(32767); --text for creating package spec and body
FUNCTION generate_spec (pkgname VARCHAR2) RETURN VARCHAR2 AS
BEGIN
RETURN 'CREATE PACKAGE ' || pkgname || ' AUTHID DEFINER AS
PROCEDURE raise_salary (emp_id NUMBER, amount NUMBER);
PROCEDURE fire_employee (emp_id NUMBER);
END ' || pkgname || ';';
ENDgenerate_spec;
FUNCTION generate_body (pkgname VARCHAR2) RETURN VARCHAR2 AS
BEGIN
RETURN'CREATE PACKAGE BODY ' || pkgname || ' AS
PROCEDURE raise_salary (emp_id NUMBER, amount NUMBER) IS
BEGIN
UPDATE employees
SET salary = salary + amount WHERE employee_id = emp_id;
END raise_salary;
PROCEDURE fire_employee (emp_id NUMBER) IS
BEGIN
DELETE FROM employees WHERE employee_id = emp_id;
END fire_employee;
END ' || pkgname || ';';
ENDgenerate_body;
BEGIN
package_text := generate_spec('emp_actions'); -- Generate package spec
EXECUTE IMMEDIATE package_text; -- Create package spec
package_text := generate_body('emp_actions'); -- Generate package body
SYS.DBMS_DDL.CREATE_WRAPPED(package_text); -- Create wrapped package body
END;
/
二. Unwrap 说明
wrap的目的是为了加密,所以Oracle并没有提供unwrap 的方法。 itpub上的一些牛人研究了一下这个问题,写了一些unwrap的代码。 具体讨论的过程,参考itpub的2个帖子:
http://www.itpub.net/thread-1154232-1-2.html
http://www.itpub.net/viewthread.php?tid=1175718&extra=page%3D1&frombbs=1
我这里贴一下unwrap 的代码:
/* Formatted on2011/8/18 12:59:54 (QP5 v5.163.1008.3004) */
CREATE OR REPLACE PACKAGE amosunwrapper
IS
FUNCTION deflate (src IN VARCHAR2)
RETURN RAW;
FUNCTION deflate (src IN VARCHAR2, quality IN NUMBER)
RETURN RAW;
FUNCTION inflate (src IN RAW)
RETURN VARCHAR2;
END;
/
CREATE OR REPLACE PACKAGE BODY amosunwrapper
IS
FUNCTION deflate (src IN VARCHAR2)
RETURN RAW
IS
BEGIN
RETURN deflate (src, 6);
END;
FUNCTION deflate (src IN VARCHAR2, quality IN NUMBER)
RETURN RAW
AS
LANGUAGE JAVA
NAME 'UNWRAPPER.Deflate( java.lang.String, int ) returnbyte[]';
FUNCTION inflate (src IN RAW)
RETURN VARCHAR2
AS
LANGUAGE JAVA
NAME 'UNWRAPPER.Inflate( byte[] ) returnjava.lang.String';
END;
/
/* Formatted on2011/8/18 13:00:16 (QP5 v5.163.1008.3004) */
CREATE OR REPLACE JAVA SOURCE NAMED UNWRAPPER
AS import java.io.*;
import java.util.zip.*;
public class UNWRAPPER
{
public static String Inflate( byte[] src )
{
try
{
ByteArrayInputStream bis = new ByteArrayInputStream( src );
InflaterInputStream iis = newInflaterInputStream( bis );
StringBuffer sb = newStringBuffer();
for( int c = iis.read(); c != -1; c = iis.read() )
{
sb.append( (char) c );
}
return sb.toString();
} catch ( Exception e )
{
}
return null;
}
public static byte[] Deflate( String src, intquality )
{
try
{
byte[] tmp = newbyte[ src.length() + 100 ];
Deflater defl = new Deflater( quality );
defl.setInput( src.getBytes( "UTF-8" ) );
defl.finish();
int cnt = defl.deflate( tmp );
byte[] res = newbyte[ cnt ];
for( int i = 0; i < cnt; i++ )
res = tmp;
return res;
} catch ( Exception e )
{
}
return null;
}
}
/
ALTER JAVA SOURCE UNWRAPPER COMPILE
/
/* Formatted on2011/8/18 13:02:57 (QP5 v5.163.1008.3004) */
--为了输出中文,要修改java过程
CREATE OR REPLACE JAVA SOURCE NAMED UNWRAPPER
AS import java.io.*;
import java.util.zip.*;
public class UNWRAPPER
{
public static String Inflate( byte[] src )
{
try
{
ByteArrayInputStream bis = newByteArrayInputStream( src );
InflaterInputStream iis = newInflaterInputStream( bis );
StringBuffer sb = newStringBuffer();
for( int c = iis.read(); c != -1; c = iis.read() )
{
sb.append( (char) c );
}
String hello = new String(sb.toString().getBytes("iso8859-1"), "GBK");
return hello;
} catch ( Exception e )
{
}
return null;
}
public static byte[] Deflate( String src, intquality )
{
try
{
byte[] tmp = newbyte[ src.length() + 100 ];
Deflater defl = new Deflater( quality );
defl.setInput( src.getBytes( "UTF-8" ) );
defl.finish();
int cnt = defl.deflate( tmp );
byte[] res = newbyte[ cnt ];
for( int i = 0; i < cnt; i++ )
res = tmp;
return res;
} catch ( Exception e )
{
}
return null;
}
}
/
ALTER JAVA SOURCE UNWRAPPER COMPILE
/
/* Formatted on2011/8/18 13:00:41 (QP5 v5.163.1008.3004) */
CREATE OR REPLACE PROCEDURE unwrap (o IN VARCHAR, n IN VARCHAR, t IN VARCHAR)
AS
vWrappedtext VARCHAR2 (32767);
vtrimtext VARCHAR2 (32767);
vChar VARCHAR2 (2);
vRepchar VARCHAR2 (2);
vLZinflatestr VARCHAR2 (32767);
nLen INTEGER;
nLoop INTEGER;
nCnt INTEGER;
code VARCHAR (512);
BEGIN
code :=
'3D6585B318DBE287F152AB634BB5A05F7D687B9B24C228678ADEA4261E03EB176F343E7A3FD2A96A0FE935561FB14D1078D975F6BC4104816106F9ADD6D5297E869E79E505BA84CC6E278EB05DA8F39FD0A271B858DD2C38994C480755E4538C46B62DA5AF322240DC50C3A1258B9C16605CCFFD0C981CD4376D3C3A30E86C3147F533DA43C8E35E1994ECE6A39514E09D64FA5915C52FCABB0BDFF297BF0A76B449445A1DF0009621807F1A82394FC1A7D70DD1D8FF139370EE5BEFBE09B97772E7B254B72AC7739066200E51EDF87C8F2EF412C62B83CDACCB3BC44EC069366202AE88FCAA4208A64557D39ABDE1238D924A1189746B91FBFEC901EA1BF7CE'; --sys.idltranslate表内容存到字符数组
vtrimtext := '';
SELECT COUNT (*)
INTO ncnt
FROM DBA_SOURCE
WHERE owner = o AND Name = n AND TYPE = t;
IF ncnt > 0 AND ncnt <= 5
THEN
FOR i IN 1 .. ncnt
LOOP
IF i = 1
THEN
SELECT RTRIM (SUBSTR (TEXT,
INSTR (TEXT,
CHR (10),
1,
20)
+ 1),
CHR (10)) --保存去掉前边20行的BASE64码正文
INTO vLZinflatestr
FROM DBA_SOURCE
WHERE owner = o AND Name = n AND TYPE = t AND line = i;
ELSE
SELECT text
INTO vLZinflatestr
FROM DBA_SOURCE
WHERE owner = o AND Name = n AND TYPE = t AND line = i;
END IF;
vtrimtext := vtrimtext || vLZinflatestr;
END LOOP;
END IF;
vtrimtext := REPLACE (vtrimtext, CHR (10), '');
nLen := LENGTH (vtrimtext) / 256;
vWrappedtext := '';
FOR i IN 0 .. nLen
LOOP
--ifi< nLen then
vWrappedtext :=
vWrappedtext
|| UTL_ENCODE.base64_decode (
UTL_RAW.cast_to_raw (SUBSTRB (vtrimtext, 256 * i + 1, 256)));
--else
--vWrappedtext:=vWrappedtext||utl_encode.base64_decode(utl_raw.cast_to_raw(substrb(vtrimtext,64*i+1 ))) ;
--endif;
--DBMS_OUTPUT.PUT_LINE(vWrappedtext);
END LOOP;
--vWrappedtext:=substr(vWrappedtext,41);
nLen := LENGTH (vWrappedtext) / 2 - 1;
vLZinflatestr := '';
FOR nLoop IN 20 .. nLen
LOOP --从第41字节开始
vChar := SUBSTRB (vWrappedtext, nLoop * 2 + 1, 2);
vLZinflatestr :=
vLZinflatestr || SUBSTR (code, TO_NUMBER (vChar, 'XX') * 2 + 1, 2); --从字符串变量匹配
--DBMS_OUTPUT.PUT_LINE(vLZinflatestr);
END LOOP;
--DBMS_OUTPUT.PUT_LINE(vLZinflatestr);
DBMS_OUTPUT.PUT_LINE (amosunwrapper.inflate (vLZinflatestr));
END;
/
黄炜弄了一个界面的Unwrap软件,下载地址:
破解(Unwrap) 10, 11G PLSQL
http://www.hellodba.com/reader.php?ID=36&lang=cn
unwrap 我们第一节创建的F_DAVE函数:
不过Oracle 对一些对象进行加密的同时,也提供了代码,比如DBMS_ROWID包。 对于该包使用unwrap 和 直接从dba_source 查询的结果是一致的,而且dba_source 还提供了注释。
SQL>exec unwrap('SYS','DBMS_ROWID','PACKAGE BODY');
SQL>select * from dba_source where name='DBMS_ROWID';
Oracle wrap 和 unwrap( 加密与解密) 说明的更多相关文章
- ORACLE 字段AES算法加密、解密
ORACLE 字段AES算法加密.解密(解决中文乱码问题)2014年02月12日 17:13:37 华智互联 阅读数:97971.加解密函数入口 CREATE OR REPLACE FUNCTION ...
- Oracle的AES加密与解密用法
Oracle的AES加密与解密用法2013年12月11日 11:50:35 iteye_751 阅读数:428--加密字符串create or replace function des3_enc( i ...
- oracle Wrap加密
wrap就是一个加密的工具 参数: Iname 输入文件的名称 Oname输出文件的名称 如何加密Oracle中的存储过程,从而在schema下看不到其源码? 软件环境: 1.操作系统:Windows ...
- oracle加密encrypt,解密decrypt
目录 oracle加密encrypt,解密decrypt 加密 解密 oracle加密encrypt,解密decrypt 有的oracle版本没有加解密函数,以下操作可以手动添加 oracle数据使用 ...
- 对称加密----AES和DES加密、解密
目前主流的加密方式有:(对称加密)AES.DES (非对称加密)RSA.DSA 调用AES/DES加密算法包最精要的就是下面两句话: Cipher cipher = Cipher.get ...
- 【转】Java Cipher类 DES算法(加密与解密)
Java Cipher类 DES算法(加密与解密) 1.加密解密类 import java.security.*; import javax.crypto.*; import java.io.*; / ...
- JS URL 使用base64加密与解密
JS编码方式: <script type="text/javascript"> document.write(encodeURI("http://www.w3 ...
- Oracle中对列加密的方法
Oracle中对列加密的方法 2011-12-22 17:21:13 分类: Linux Oracle支持多种列加密方式: 1,透明数据加密(TDE):create table encrypt_col ...
- Java加密与解密笔记(四) 高级应用
术语列表: CA:证书颁发认证机构(Certificate Authority) PEM:隐私增强邮件(Privacy Enhanced Mail),是OpenSSL使用的一种密钥文件. PKI:公钥 ...
随机推荐
- 解决Activity启动黑屏和设置android:windowIsTranslucent不兼容activity切换动画的问题
在该项目中遇到开Activity之后,黑屏问题,解决的办法是在网上通过设置发现theme和style特性,可以实现. http://www.cnblogs.com/sunzn/p/3407078.ht ...
- win8 iis7/iis8 安装、卸载、设置方法
原文:win8 iis7/iis8 安装.卸载.设置方法 一.安装 自从升级到Win8之后,之前使用已经趋于熟悉的iis7.0被取而代之的是iis8.0,那么安装和获取方法也就产生的略微的变化,为了避 ...
- Round #169 (Div. 2)D. Little Girl and Maximum XOR
1.首先是要找到一个位置从左至右,作l这一个是0,r这一个是1. 2.实例01011,10100.你将能够找到01111和10000. #include<cstdio> #include& ...
- (大数据工程师学习路径)第三步 Git Community Book----中级技能(下)
一.追踪分支 1.追踪分支 在Git中‘追踪分支’是用于联系本地分支和远程分支的. 如果你在’追踪分支'(Tracking Branches)上执行推送(push)或拉取(pull)时,它会自动推送( ...
- PHP IOS PUSH Demo
<?php // Put your device token here (without spaces): $deviceToken = '679b466b030038bed6c3a2563c7 ...
- Java中间(三十五)-----Java详细设置(一个):请指定初始容量设置
集合是我们在Java编程中使用很广泛的,它就像大海,海纳百川,像万能容器,盛装万物.并且这个大海,万能容器还能够无限变大(假设条件同意). 当这个海.容器的量变得很大的时候,它的初始容量就会显得很重要 ...
- Android pm命令用法
Sam综观有关PackageManager时,无意中发现Android 下提供一个pm命令,通常放在/system/bin/下. 这个命令与Package有关.且很有用.所以研究之. 0. Usage ...
- AngularJS与ASP.NET MVC登录超时解决方案
问题: 1.在Action中判断Ajax请求的方法Request.IsAjaxRequest()始终是false 2.返回给前台StatusCode和HttpUnauthorizedResult,前台 ...
- Android 4.4(KitKat)表格管理子系统 - 骨架
原文地址:http://blog.csdn.net/jinzhuojun/article/details/37737439 窗体管理系统是Android中的主要子系统之中的一个.它涉及到App中组件的 ...
- Nyoj 一笔画问题(图论)
描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N&l ...