Using DBMS CRYPTO package to encrypt data in a table


 

 

Create or replace package cryptit is
Function encrypt_data( p_data IN VARCHAR2 ) Return RAW DETERMINISTIC;
Function decrypt_data( p_data IN RAW ) Return VARCHAR2 DETERMINISTIC;
End cryptit;
/
-------------------------------------------------
 
Create or replace package body cryptit is
V_Key       RAW(128) := UTL_RAW.cast_to_raw('testkey1');
  Function encrypt_data( p_data IN VARCHAR2 ) Return RAW DETERMINISTIC
IS
   l_data RAW(2048) := utl_raw.cast_to_raw(p_data);
   l_encrypted RAW(2048);
   BEGIN
   NULL;
   l_encrypted := dbms_crypto.encrypt
( src => l_data,
                 typ => DBMS_CRYPTO.DES_CBC_PKCS5,
   key => V_KEY );
   Return l_encrypted;
END encrypt_data;
Function decrypt_data( p_data IN RAW ) Return VARCHAR2 DETERMINISTIC
   IS
l_decrypted RAW(2048);
BEGIN
l_decrypted := dbms_crypto.decrypt
 ( src => p_data,
typ => DBMS_CRYPTO.DES_CBC_PKCS5,
key => V_KEY );
Return utl_raw.cast_to_varchar2(l_decrypted);
END decrypt_data;
End cryptit;
/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: