• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1160
  • Last Modified:

Encrypt and Decrypt

I need to storage in a variable a varchar encrypted and decrypt that same variable. I get the following error: PLS-00307: too many declarations of 'DESENCRYPT' match this call in the lines:
encryptedString := sys.dbms_obfuscation_toolkit.DESEncrypt(vlsPassword, vlsKey);
and
sys.dbms_obfuscation_toolkit.DESDecrypt(encryptedString, vlsKey, decryptedString );
DECLARE 
 
		encryptedString  VARCHAR2(100); 		               
		decryptedString  VARCHAR2(100);
		vlsPassword		 VARCHAR2(20);
		vlsKey			 VARCHAR2(20);
 
 
BEGIN 
  
  vlsPassword := 'TOPSECRET';
  vlsKey 	  := 'MYKEY';
  
  encryptedString := sys.dbms_obfuscation_toolkit.DESEncrypt(vlsPassword, vlsKey); 
  
  DBMS_OUTPUT.PUT_LINE('ENCRYPTED: '|| encryptedString);
  
  sys.dbms_obfuscation_toolkit.DESDecrypt(encryptedString, vlsKey, decryptedString );
  
  DBMS_OUTPUT.PUT_LINE('DECRYPTED: '|| decryptedString);
  
END;

Open in new window

0
itzy
Asked:
itzy
1 Solution
 
lwadwellCommented:
Hi itzy,

Your error, as I understand it, is due to Oracle not being able to figure out which of the overloaded procedure versions to call.  With the help of this article, http://www.databasejournal.com/features/oracle/article.php/3358671/Decrypting-Oracles-DBMSOBFUSCATIONTOOLKIT.htm, I managed to get a working version.

Note that the only way I could get it work was to ensure the length of the 'key' was 8 bytes and the length of the string to be encrypted was a multiple of 8 bytes.

lwadwell
DECLARE 
 
    encryptedString  VARCHAR2(2048);                            
    decryptedString  VARCHAR2(2048);
    vlsPassword      VARCHAR2(80)       := 'TOPSECRET';
    vlsKey           VARCHAR2(8)        := 'MYKEY';
 
 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 ***'; 
BEGIN 
  
  vlsPassword := RPAD(vlsPassword, 8 * (TRUNC(LENGTH(vlsPassword)/8) + 1));
  vlsKey      := RPAD(vlsKey, 8);
  
--  encryptedString := 
  DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT( input_string     => vlsPassword, 
                                       key_string       => vlsKey,
                                       encrypted_string => encryptedString); 
  DBMS_OUTPUT.PUT_LINE('ENCRYPTED: '|| encryptedString || '!');
  
  DBMS_OBFUSCATION_TOOLKIT.DESDECRYPT( input_string     => encryptedString, 
                                       key_string       => vlsKey, 
                                       decrypted_string => decryptedString);
  DBMS_OUTPUT.PUT_LINE('DECRYPTED: '|| decryptedString || '!');
  
EXCEPTION
   WHEN error_in_input_buffer_length THEN
      DBMS_OUTPUT.PUT_LINE('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);
END;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now