User passwords of many applications are encrypted and stored in the database. Some use MD5 hash strings. However, because the MD5 algorithm is irreversible, only one other password can be set at a time. The following uses the 10g DBMS_CRYPTO package for encryption and decryption to solve the above problems. After testing, it supports Chinese (10.2, and the database character set is AL32UTF8), and the encryption and decryption speed is fast. Complete DBMS_CRYPTO package reference in http://blog.csdn.net/wzy0623/archive/2007/06/14/1652032.aspx
Run the DBMS_CRYPTO package with sys user authorization:
Grant execute on sys. DBMS_CRYPTO TO username;
Encryption function:
Create or replace function fn_getencval (p_key IN VARCHAR2, p_in IN VARCHAR2)
RETURN VARCHAR2
IS
Rochelle enc_val VARCHAR2 (256 );
Rochelle in_raw RAW (128): = UTL_I18N.string_to_raw (p_in );
Rochelle key_raw RAW (128): = UTL_I18N.string_to_raw (RPAD (p_key, 96, 'x '));
Rochelle mod NUMBER
: = DBMS_CRYPTO.hash_sh1 + DBMS_CRYPTO.chain_ecb + DBMS_CRYPTO.pad_zero;
BEGIN
Rochelle enc_val: =
UTL_I18N.raw_to_char (DBMS_CRYPTO.encrypt (l_in_raw, l_mod, l_key_raw ));
RETURN l_enc_val;
END;
Decryption function:
Create or replace function fn_getdecval (p_key IN VARCHAR2, p_in IN VARCHAR2)
RETURN VARCHAR2
IS
Rochelle enc_val VARCHAR2 (256 );
Rochelle in_raw RAW (128): = UTL_I18N.string_to_raw (p_in );
Rochelle key_raw RAW (128): = UTL_I18N.string_to_raw (RPAD (p_key, 96, 'x '));
Rochelle mod NUMBER
: = DBMS_CRYPTO.hash_sh1 + DBMS_CRYPTO.chain_ecb + DBMS_CRYPTO.pad_zero;
BEGIN
Rochelle enc_val: =
UTL_I18N.raw_to_char (DBMS_CRYPTO.decrypt (l_in_raw, l_mod, l_key_raw ));
RETURN l_enc_val;
END;