System Packages Oracle PLSQL

SQL> CREATE OR REPLACE FUNCTION get_enc_val (
  2     p_in_val   IN   VARCHAR2,
  3     p_key      IN   VARCHAR2,
  4     p_iv       IN   VARCHAR2 := NULL,
  5     p_which    IN   NUMBER := 0
  6  )
  7     RETURN VARCHAR2
  8  IS
  9     l_enc_val   VARCHAR2 (200);
 10     l_in_val    VARCHAR2 (200);
 11     l_iv        VARCHAR2 (200);
 12  BEGIN
 13     IF p_which = 0
 14     THEN
 15        IF LENGTH (p_key) < 16
 16        THEN
 17           raise_application_error
 18                                 (-20001,
 19                                  'Key length less than 16 for two-pass scheme'
 20                                 );
 21        END IF;
 22     ELSIF p_which = 1
 23     THEN
 24        IF LENGTH (p_key) < 24
 25        THEN
 26           raise_application_error
 27                               (-20002,
 28                                'Key length less than 24 for three-pass scheme'
 29                               );
 30        END IF;
 31     ELSE
 32        raise_application_error (-20003,
 33                                    'Incorrect value of which '
 34                                 || p_which
 35                                 || '; must be 0 or 1'
 36                                );
 37     END IF;
 38
 39     l_in_val := RPAD (p_in_val, (8 * ROUND (LENGTH (p_in_val) / 8, 0) + 8));
 40     l_iv := RPAD (p_iv, (8 * ROUND (LENGTH (p_iv) / 8, 0) + 8));
 41     l_enc_val :=
 42        DBMS_OBFUSCATION_TOOLKIT.des3encrypt (input_string      => l_in_val,
 43                                              key_string        => p_key,
 44                                              iv_string         => l_iv,
 45                                              which             => p_which
 46                                             );
 47     l_enc_val := RAWTOHEX (UTL_RAW.cast_to_raw (l_enc_val));
 48     RETURN l_enc_val;
 49  END;
 50  /
Function created.
SQL>