oracle使用3DES加密
Posted 阮減显
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle使用3DES加密相关的知识,希望对你有一定的参考价值。
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加密的主要内容,如果未能解决你的问题,请参考以下文章