oracle常用加解密函数

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;
select md5() from dual

DES加密

create or replace function
encrypt_des(p_text varchar2, p_key varchar2) return varchar2 is
v_text varchar2();
v_enc varchar2();
raw_input RAW() ;
key_input RAW() ;
decrypted_raw RAW();
begin
v_text := rpad( p_text, (trunc(length(p_text)/)+)*, chr());
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;
select encrypt_des('test', 'key123456789') from dual;

DES解密

create or replace function decrypt_des(p_text varchar2,p_key varchar2) return varchar2 is
v_text varchar2();
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());
dbms_output.put_line(v_text);
return v_text;
end;
select decrypt_des('test', 'key123456789') from dual;
上一篇:ubuntu命令行添加拥有管理员权限新用户


下一篇:Restful是什么,SOAP Webservice和RESTful Webservice