Example on how to Encrypt-Decrypt data
                                                 Last update (2008-03-04 16:42:09)
                                                                                                                   Date added (2008-03-04 16:40:54)

Summary
A simple pl/sql script to encrypt and decrypt a string. It uses the Dbms_obfuscation_toolkit package.
SET serveroutput ON
DECLARE
   input_string                  CHAR ( 16 ) := '123456789';
   key_string                    VARCHAR2 ( 16 ) := '0racle9iOracle9i';
   encrypted_string              VARCHAR2 ( 2048 );
   decrypted_string              VARCHAR2 ( 2048 );
   error_in_input_buffer_length  EXCEPTION;
   PRAGMA EXCEPTION_INIT ( error_in_input_buffer_length, -28232 );
   INPUT_BUFFER_LENGTH_ERR_MSG   VARCHAR2 ( 100 ) := '*** DES INPUT BUFFER NOT A MULTIPLE OF 8 BYTES ***';
-- 1. Test string data encryption and decryption
-- The interface for encrypting raw data is similar.
BEGIN
   DBMS_OUTPUT.PUT_LINE ( '========= BEGIN TEST =========' );
   DBMS_OUTPUT.PUT_LINE ( 'Input String :' || input_string );
   Dbms_Obfuscation_Toolkit.DES3Encrypt ( input_string => input_string
                                        ,key_string => key_string
                                        ,encrypted_string => encrypted_string
                                       );
   DBMS_OUTPUT.PUT_LINE ( 'Encrypted string : ' || encrypted_string );
   Dbms_Obfuscation_Toolkit.DES3Decrypt ( input_string => encrypted_string
                                        ,key_string => key_string
                                        ,decrypted_string => decrypted_string
                                       );
   DBMS_OUTPUT.PUT_LINE ( 'Decrypted output : ' || decrypted_string );
   DBMS_OUTPUT.PUT_LINE ( '' );

   IF input_string = decrypted_string THEN
      DBMS_OUTPUT.PUT_LINE ( 'DES Encryption and Decryption successful' );
   END IF;
EXCEPTION
   WHEN error_in_input_buffer_length THEN
      DBMS_OUTPUT.PUT_LINE ( '' || INPUT_BUFFER_LENGTH_ERR_MSG );
END;
/
Reviews
Filters
Search