Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Problem Decrypting in-memory
ohaya wrote:
>
> Hi,
>
> I have one procedure to encrypt:
>
> CREATE or REPLACE PROCEDURE encrypt_password (key_string IN varchar2,
> uname IN varchar2, password IN varchar2) IS
>
> input_string VARCHAR2(16) := to_char(password);
> encrypted_string VARCHAR2(2048);
>
> raw_encrypted_data RAW(128);
>
> BEGIN
> dbms_obfuscation_toolkit.DESEncrypt(
> input_string => input_string,
> key_string => key_string,
> encrypted_string => encrypted_string);
> raw_encrypted_data := UTL_RAW.CAST_TO_RAW(encrypted_string);
> dbms_output.put_line('Hex-RAW raw_encrypted_data: ' ||
> rawtohex(raw_encrypted_data));
> UPDATE LHDB set secure_pwd = encrypted_string WHERE username = uname;
> COMMIT;
>
> END;
> /
>
> When I execute that in SQLPlus, I get:
>
> SQL> exec encrypt_password('12345678', 'test1', 'testtesttesttest');
> Hex-RAW raw_encrypted_data: 7B62AA0B153BC965D7B8D0E529F6222A
>
> PL/SQL procedure successfully completed.
>
> SQL>
>
> Now, I have another procedure that I want to use to decrypt a password
> that is in memory (rather than in a table):
>
> CREATE or REPLACE PROCEDURE decrypt_password_inmemory (key_string IN
> varchar2, encrypted_string IN varchar2, decrypted OUT varchar2) IS
>
> encrypted_raw RAW(128) := UTL_RAW.CAST_TO_RAW(encrypted_string);
> key_raw RAW(128) := UTL_RAW.CAST_TO_RAW(key_string);
>
> decrypted_raw RAW(128);
> -- decrypted_string VARCHAR2(2048);
>
> BEGIN
> dbms_obfuscation_toolkit.DESDecrypt(
> input => encrypted_raw,
> key => key_raw,
> decrypted_data => decrypted_raw);
>
> decrypted := UTL_RAW.CAST_TO_VARCHAR2(decrypted_raw);
> dbms_output.put_line('Decrypted Password is: ' || decrypted);
> END;
> /
>
> When I try to execute this procedure, I'm getting what looks like RAW
> data?
>
> SQL> var
> variable x
> datatype VARCHAR2(100)
> SQL> exec decrypt_password_inmemory('12345678',
> '7B62AA0B153BC965D7B8D0E529F6222
> A', :x);
> Decrypted Password is: -¡-*|X_Ñ?=Ää˜KÿX+Xµ·4Gj+¦Æ+uP$n-
>
> PL/SQL procedure successfully completed.
>
> X
> --------------------------------------------------------------------------------
>
> -¡-*|X_Ñ?=Ää˜KÿX+Xµ·4Gj+¦Æ+uP$n-
>
> Can anyone tell me what's wrong with this 'in-memory' procedure?
>
> How do I get the original password (testtesttesttest) back as a
> varchar2?
>
> Thanks,
> Jim
Hi,
Sorry, I just figure it out. I should have used 'hextoraw()' for setting the encrypted_raw in the procedure!!!
It works now!!
Jim Received on Tue Jun 21 2005 - 10:05:22 CDT
![]() |
![]() |