Create or Replace package Pg_encrypt_decrypt
Is
Ikey VARCHAR2 (8): = ' oracle9i ';
function Gen_raw_key (Ikey in varchar2) return RAW;
function Decrypt_3key_mode (ivalue in Raw,imode on Pls_integer) return varchar2;
function Encrypt_3key_mode (ivalue in Varchar2,imode on Pls_integer) return raw;
function Formatstr (ivalue in varchar2) return varchar2;
function FormatStr2 (ivalue in varchar2) return varchar2;
End
/////////
Create or replace package body Pg_encrypt_decrypt
Is
function Gen_raw_key (Ikey in VARCHAR2)
Return RAW
As
Rawkey Raw (240): = ';
Begin
For I in 1..length (Ikey) loop
Rawkey: = rawkey| | Hextoraw (To_char (ASCII (substr (Ikey, I, 1)));
End Loop;
return rawkey;
End Gen_raw_key;
/* Creating function decrypt_3key_mode*/
FUNCTION Decrypt_3key_mode (Ivalue in Raw, imode in Pls_integer) return VARCHAR2
As
vdecrypted varchar2 (4000);
Rawkey Raw (240): = ';
Begin
Rawkey: = Gen_raw_key (Ikey);--Decrypt input string
vdecrypted: = Dbms_obfuscation_toolkit.des3decrypt (Utl_raw. CAST_TO_VARCHAR2 (ivalue), key_string => Rawkey, which =>);
Return FormatStr2 (vdecrypted);
End Decrypt_3key_mode;
/*creating function encrypt_3key_mode*/
FUNCTION Encrypt_3key_mode (Ivalue in Varchar2, Imode in Pls_integer) return raw
As
vencrypted varchar2 (4000);
Vencryptedraw Raw (2048);
Rawkey Raw (240): = ';
Begin
Rawkey: = Gen_raw_key (Ikey);--Encrypt input string
vencrypted: = Dbms_obfuscation_toolkit.des3encrypt (Formatstr (ivalue), key_string => Rawkey, which =>);
--Convert to Raw as out
Vencryptedraw: = Utl_raw. Cast_to_raw (vencrypted);
return vencryptedraw;
End Encrypt_3key_mode;