(1)des加密函数
create or replace function encrypt_des(p_text varchar2, p_key varchar2) return varchar2 is v_text varchar2(4000); v_enc varchar2(4000); raw_input raw(128) ; key_input raw(128) ; decrypted_raw raw(2048); begin v_text := rpad( p_text, (trunc(length(p_text)/8)+1)*8, chr(0)); raw_input := utl_raw.cast_to_raw(v_text); key_input := utl_raw.cast_to_raw(p_key); dbms_obfuscation_toolkit.desencrypt(input => raw_input,key => key_input,encrypted_data =>decrypted_raw); v_enc := rawtohex(decrypted_raw); dbms_output.put_line(v_enc); return v_enc; end;
(2)des解密函数
create or replace function decrypt_des(p_text varchar2,p_key varchar2) return varchar2 is v_text varchar2(2000); begin dbms_obfuscation_toolkit.desdecrypt(input_string => utl_raw.cast_to_varchar2(p_text),key_string =>p_key, decrypted_string=> v_text); v_text := rtrim(v_text,chr(0)); dbms_output.put_line(v_text); return v_text; end;
(3)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;
(4)函数使用示例
des加密: update tb_salarysign_staff s set s.staffpwd =encrypt_des(s.staffpwd, ‘test#5&124*!de’);
des解密:select decrypt_des(s.staffpwd, ‘test#5&124*!de’) from tb_salarysign_staff s
md5加密: update tb_salarysign_staff s set s.staffpwd = md5(s.staffpwd);
ps:关于加密运算,这里再为大家提供几款比较实用的工具供大家参考使用:
md5在线加密工具:
http://tools.jb51.net/password/createmd5password
在线散列/哈希算法加密工具:
在线md5/hash/sha-1/sha-2/sha-256/sha-512/sha-3/ripemd-160加密工具:
在线sha1/sha224/sha256/sha384/sha512加密工具: