(1) des cryptographic functions
Create or replace functionencrypt_des (P_text varchar2, P_key varchar2) return varchar2 isv_text varchar2 (4000); V_enc Varc HAR2 (4000); Raw_input Raw (Key_input raw);d Ecrypted_raw Raw (2048) Beginv_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);d Bms_obfuscation_toolkit. Desencrypt (input = Raw_input,key = Key_input,encrypted_data =>decrypted_raw); V_enc: = Rawtohex (decrypted_ Raw);d bms_output.put_line (V_ENC); return v_enc;end;
(2) des decryption function
Create or Replace function decrypt_des (p_text varchar2,p_key varchar2) return varchar2 isv_text varchar2 (+); Begindbms _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));d Bms_ Output.put_line (V_text); return v_text;end;
(3) MD5 encryption function
CREATE OR REPLACE FUNCTION MD5 (passwd in VARCHAR2) RETURN varchar2isretval varchar2 (32); Beginretval: = Utl_raw.cast_to_raw (Dbms_obfuscation_toolkit. MD5 (input_string = passwd)); RETURN retval; END;
(4) Example of function use
DES encryption: Update tb_salarysign_staff S set s.staffpwd =encrypt_des (s.staffpwd, ' test#5&124*!de ');
Des decryption: Select Decrypt_des (s.staffpwd, ' Test#5&124*!de ') from Tb_salarysign_staff s
MD5 encryption: Update Tb_salarysign_staff s set s.staffpwd = MD5 (S.STAFFPWD);