subscribe: Posts | Comments

DBMS_OBFUSCATION_TOOLKIT

0 comments

pic5

The DBMS_OBFUSCATION_TOOLKIT package provides two DES (Data Encryption Standard) procedures for string inputs and raw inputs:

DESEncrypt  procedure

DESDecrypt procedure

The sample use of the package.

SQL> variable x varchar2(25)

SQL> exec :x := ‘How are you';

SQL>print x
X

The DBMS_OBFUSCATION_TOOLKIT package provides two DES (Data Encryption Standard) procedures for string inputs and raw inputs:

DESEncrypt  procedure

DESDecrypt procedure

The sample use of the package.

SQL> variable x varchar2(25)

SQL> exec :x := ‘How are you';

SQL>print x
X
——————————–
How are you

SQL> create or replace procedure crypt( p_str in out varchar2 )
    as
        l_data  varchar2(255);
    begin
        l_data := rpad( p_str, (trunc(length(p_str)/8)+1)*8, chr(0) );  —– trick is to make sure everything is a multiple 8 bytes  
        dbms_obfuscation_toolkit.DESEncrypt
            ( input_string => l_data,
              key_string   => ‘MagicKey’,    —– 8 bytes
              encrypted_string=> p_str );
   end;
 /
Procedure created.

SQL> create or replace procedure decrypt( p_str in out varchar2 )
    as
        l_data  varchar2(255);
    begin
        dbms_obfuscation_toolkit.DESDecrypt
            ( input_string => p_str,
              key_string   => ‘MagicKey’,
             decrypted_string=> l_data );  
       p_str := rtrim( l_data, chr(0) );
   end;
/

Procedure created.

SQL>exec crypt(:x)    —– print the result and it should be Encrypted

SQL>exec decrypt(:x)  —– print the result and it should be Decrypted