1. 程式人生 > >oracle數據庫加密腳本

oracle數據庫加密腳本

oracle加密腳本

----權限設置
grant execute on DBMS_CRYPTO to username;
---------加密
create or replace function encrypt256(v_input varchar2) return raw
is
v_result raw(1999);
c_key char(32) := ‘1q2wa3es4rz5tx6ycD*UF8tif9ogjen2‘;
begin
v_result := sys.DBMS_CRYPTO.ENCRYPT(
UTL_I18N.STRING_TO_RAW(v_input, ‘AL32UTF8‘),
sys.DBMS_CRYPTO.ENCRYPT_AES256+sys.DBMS_CRYPTO.CHAIN_CBC+sys.DBMS_CRYPTO.PAD_PKCS5,
UTL_I18N.STRING_TO_RAW(c_key, ‘AL32UTF8‘));
return v_result;
end;
-----------解密
create or replace function decrypt256(v_input raw) return varchar2
is
v_result raw(1999);
c_key char(32) := ‘1q2wa3es4rz5tx6ycD*UF8tif9ogjen2‘;
begin
v_result := SYS.DBMS_CRYPTO.DECRYPT(
v_input,
SYS.DBMS_CRYPTO.ENCRYPT_AES256+SYS.DBMS_CRYPTO.CHAIN_CBC+SYS.DBMS_CRYPTO.PAD_PKCS5,
UTL_I18N.STRING_TO_RAW(c_key, ‘AL32UTF8‘));
return UTL_I18N.RAW_TO_CHAR(v_result, ‘AL32UTF8‘);
end;
----MD5加密
CREATE OR REPLACE FUNCTION MD5(passwd IN VARCHAR2) RETURN VARCHAR2 IS
  retval varchar2(32);
BEGIN
  retval := utl_raw.cast_to_raw(DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT_STRING => passwd));
  RETURN retval;
END;


oracle數據庫加密腳本