Chinaunix首页 | 论坛 | 博客
  • 博客访问: 11676236
  • 博文数量: 8065
  • 博客积分: 10002
  • 博客等级: 中将
  • 技术积分: 96708
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-16 17:06
文章分类

全部博文(8065)

文章存档

2008年(8065)

分类: 服务器与存储

2008-04-21 12:41:19

create or replace package PG_ENCRYPT_DECRYPT
is
iKey varchar2(8):='oracle9i';
function GEN_RAW_KEY  ( iKey in varchar2) return raw;
function DECRYPT_3KEY_MODE(iValue in raw,iMode in pls_integer)return varchar2;

 
function ENCRYPT_3KEY_MODE(iValue in varchar2,iMode in pls_integer)return raw;
function FormatStr(iValue in varchar2)return varchar2;
function FormatStr2(iValue in varchar2)return varchar2;
end;
/////////
create or replace package body PG_ENCRYPT_DECRYPT
is
  function GEN_RAW_KEY  ( iKey in varchar2)
  return raw
  as
    rawkey raw(240) := '';
  begin
    for i in 1..length(iKey) loop   
       rawkey := rawkey||hextoraw(to_char(ascii(substr(iKey, i, 1))));
    end loop;
    return rawkey;
  end GEN_RAW_KEY;
  /* Creating function DECRYPT_3KEY_MODE*/
  FUNCTION DECRYPT_3KEY_MODE  ( iValue in raw, iMode in pls_integer)return varchar2
  as
    vDecrypted varchar2(4000);
    rawkey raw(240) := '';
  begin
       rawkey := GEN_RAW_KEY(iKey);-- decrypt input string
       vDecrypted := dbms_obfuscation_toolkit.des3decrypt (UTL_RAW.CAST_TO_VARCHAR2(iValue), key_string => rawkey, which => iMode);
       return FormatStr2(vDecrypted);
  end DECRYPT_3KEY_MODE;
  /*Creating function ENCRYPT_3KEY_MODE*/
  FUNCTION ENCRYPT_3KEY_MODE  ( iValue in varchar2,  iMode in pls_integer)return raw
  as
    vEncrypted varchar2(4000);
    vEncryptedRaw Raw(2048);
    rawkey raw(240) := '';
  begin
    rawkey := GEN_RAW_KEY(iKey);-- encrypt input string
    vEncrypted := dbms_obfuscation_toolkit.des3encrypt (FormatStr(iValue), key_string => rawkey, which => iMode);
    -- convert to raw as out
    vEncryptedRaw := UTL_RAW.CAST_TO_RAW(vEncrypted);
    return vEncryptedRaw;
  end ENCRYPT_3KEY_MODE;
阅读(1503) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~