(1) DES encryption function
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 decryption function
Create or Replace function decrypt_des (p_text varchar2,p_key varchar2) return varchar2 is
v_text varchar2 (Watts);
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 encryption function
CREATE OR REPLACE FUNCTION MD5 (passwd in VARCHAR2) return
VARCHAR2
is
retval varchar2 (a);
BEGIN
retval: = Utl_raw.cast_to_raw (Dbms_obfuscation_toolkit. MD5 (input_string => passwd));
return retval;
End;
(4) Example of function usage
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);
PS: About encryption operations, here again for you to provide a few more practical tools for everyone to refer to the use of:
MD5 Online Encryption Tool:
Http://tools.jb51.net/password/CreateMD5Password
Online hashing/hashing algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt
Online md5/hash/sha-1/sha-2/sha-256/sha-512/sha-3/ripemd-160 Encryption Tool:
Http://tools.jb51.net/password/hash_md5_sha
Online sha1/sha224/sha256/sha384/sha512 Encryption Tool:
Http://tools.jb51.net/password/sha_encode