当前位置:Gxlcms > 数据库问题 > oracle使用3DES加密

oracle使用3DES加密

时间:2021-07-01 10:21:17 帮助过:25人阅读

 

CREATE OR REPLACE PACKAGE dbc_cryptor IS
  SYSKEY VARCHAR2(16) := ‘0000000012345678‘;
  FUNCTION encrypt_3des(v_str IN VARCHAR2,
                        v_key IN VARCHAR2 DEFAULT SYSKEY) RETURN RAW;
  FUNCTION decrypt_3des(v_raw IN RAW, v_key IN VARCHAR2 DEFAULT SYSKEY)
    RETURN VARCHAR2;
END;
/

CREATE OR REPLACE PACKAGE BODY dbc_cryptor IS

FUNCTION encrypt_3des(v_str IN VARCHAR2, v_key IN VARCHAR2 DEFAULT SYSKEY) RETURN RAW AS
v_str_raw RAW(2048);
BEGIN

if v_str is null then 
   RETURN NULL;
end if;

if (MOD(LENGTHB(v_str), 8) > 0) then 
   v_str_raw := UTL_RAW.CAST_TO_RAW(RPAD(v_str, (floor(LENGTHB(v_str)/8)+1)*8, chr(0))); 
else 
   v_str_raw := UTL_RAW.CAST_TO_RAW(v_str);
end if;

return DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(input => v_str_raw, key => UTL_RAW.CAST_TO_RAW(v_key), which => 0, iv => NULL);

END;

FUNCTION decrypt_3des(v_raw IN raw, v_key IN VARCHAR2 DEFAULT SYSKEY) RETURN VARCHAR2 AS

BEGIN

if v_raw is null or MOD(LENGTH(v_raw), 16) <> 0 then 
   RETURN NULL;
end if;

return UTL_RAW.CAST_TO_VARCHAR2(DBMS_OBFUSCATION_TOOLKIT.DES3Decrypt(input => v_raw, key => UTL_RAW.CAST_TO_RAW(v_key), which => 0, iv => NULL));

END;
END;
/

 

oracle使用3DES加密

标签:ati   length   varchar   arc   creat   pre   加密   class   pac   

人气教程排行