oracle用存储过程加密一段字符串(3des算法)

2016-01-29 14:43 153 1 收藏

oracle用存储过程加密一段字符串(3des算法),oracle用存储过程加密一段字符串(3des算法)

【 tulaoshi.com - Oracle教程 】

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;

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com)

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com)[next]

function FormatStr(iValue in varchar2)return varchar2
  as
  begin
      declare
        i number;
        j number;
        m_value varchar2(4000);
      begin
           m_value:=iValue;
           i:=(length(m_value) mod 8);
           if i<0 then
             j:=1;
             for j in 1..(8-i) loop
                 m_value:=m_value||'#';
             end loop;            
           end if;
           return m_value;  
      end; 
  end FormatStr;
 
  function FormatStr2(iValue in varchar2)return varchar2
  as
  begin
      declare
        i number;
        j number;
        m_value varchar2(4000);
      begin
           m_value:=iValue;
  &n

来源:http://www.tulaoshi.com/n/20160129/1494044.html

延伸阅读
C#中字符串的加密可以用DSA和RSA,先要将字符串转换为字节数组,这与编码有关。再选择签名方式,有RSA和DSA,sign便是出来的签名结果。 可以用DSA和RSA,如: using System; using System.Text; using System.Security.Cryptography; class dsacrypto_SignData { public static void Main(String[] args){ //...
标签: ASP
function mis(preString) Dim texts Dim seed Dim i,length prestring = trim(preString) length = len(preString) seed = length texts = "" for i = 1 to length seed = int(94*rnd(-asc(mid(preString,i,1))-seed*asc(right(prestring,1)))+32) texts = texts & chr(seed) & chr(int(94*rnd(-seed)+32)) next dim dist dist="" for i...
标签: PHP
作者:jeffwu(327wu@263.net) [code:1:e818e36f81] /* 功能:截取全角和半角混合的字符串以避免乱码 参数: $str_cut 需要截断的字符串 $length  允许字符串显示的最大长度 */ function substr_cut($str_cut,$length = 30){  if (strlen($str_cut) $length){   for($i=0; $i < $length; $i++) &...
方法1: X:\oracle\ora81\bin\wrap   iname=XXX   oname=XXX    方法2:9i在win2000下使用wrap加密存储过程,10g可以用加密包dbms_ddl.wrap或dbms_ddl.create_wrapped。 11.5.1 在win2000下使用wrap加密存储过程 wrap.bat rem 使用方法:wrap 待加密的文件名 set ...
/** * 字符串分割 * * @author * @param str java.lang.String 要分割的字符串 * @param sp java.lang.String 需要被替换的子串 * @return 替换之后的字符串 * @return 分割失败,返回null */ public static String[] Split(String str, String sp) { StringTokenizer st = new StringTokenizer...

经验教程

768

收藏

27
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部