SQL> connect / as sysdba
SQL> @$ORACLE_HOME/rdbms/admin/dbmsobtk.sql
SQL> @$ORACLE_HOME/rdbms/admin/prvtobtk.plb
SQL> GRANT execute ON dbms_obfuscation_toolkit TO public;
CREATE OR REPLACE PACKAGE CryptIT AS
FUNCTION encrypt( Str VARCHAR2,
hash VARCHAR2 ) RETURN VARCHAR2;
FUNCTION decrypt( xCrypt VARCHAR2,
hash VARCHAR2 ) RETURN VARCHAR2;
END CryptIT;
/
CREATE OR REPLACE PACKAGE BODY CryptIT AS
crypted_string VARCHAR2(2000);
FUNCTION encrypt( Str VARCHAR2, hash VARCHAR2 ) RETURN VARCHAR2 AS
pieces_of_eight INTEGER := ((FLOOR(LENGTH(Str)/8 + .9)) * 8);
BEGIN
dbms_obfuscation_toolkit.DESEncrypt(
input_string => RPAD( Str, pieces_of_eight ),
key_string => RPAD(hash,8,'#'),
encrypted_string => crypted_string );
RETURN crypted_string;
END;
FUNCTION decrypt( xCrypt VARCHAR2, hash VARCHAR2 ) RETURN VARCHAR2 AS
BEGIN
dbms_obfuscation_toolkit.DESDecrypt(
input_string => xCrypt,
key_string => RPAD(hash,8,'#'),
decrypted_string => crypted_string );
RETURN trim(crypted_string);
END;
END CryptIT;
/
SQL> grant execute on CryptIT to public;
SQL> connect scott/tiger
SQL> select sys.cryptIT.encrypt('1111', 'linux.anzinda.com') from dual;
SQL> connect / as sysdba
SQL> revoke execute on CryptIT from public;
SQL> drop package CryptIT;
SQL> conn scott/tiger
-- Package를 별도로 scott(임의의 계정)의 스키마로 새로 생성한다.
SQL> select cryptIT.encrypt('1111', 'linux.anzinda.com') from dual;