How To Encrypt Data Elements Using PLSQL
How To Encrypt Data Elements Using PLSQL
I am not the original creator of this plsql procedure. Just used this script some days ago, and stored at my local computer. Unable to locate the source website. Hence, sharing it with you. The copyright and credit goes to the Author. DECLARE =========================================================================== DESCRIPTION Example on how to encrypt data elements ============================================================================= input_string input_string key_string encrypted_string decrypted_string VARCHAR2 ( 16 ) := tigertigertigert; CHAR ( 16 ) := 123456789; VARCHAR2 ( 16 ) := 0racle9i0racle9i; VARCHAR2 ( 2048 ); 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;