2

I have created this function for decrypt a password and its working but is showing strange characters like this ��5d[���������. I'm using oracle xe 10g

create or replace
function decrypt (val VARCHAR) return varchar2 is

input_string varchar2(2048) := val;
key_string VARCHAR2(10) := 'xpto';
decrypted_string VARCHAR2(2048);

begin

 dbms_output.put_line(input_string);

 dbms_obfuscation_toolkit.DESDecrypt(
                                input_string => input_string, 
                                key_string => key_string, 
                                decrypted_string => decrypted_string );

 dbms_output.put_line('> decrypted string output : ' || decrypted_string);
 return decrypted_string;
 end;

What i'm i doing wrong it should appear a readable string.

macwadu
  • 907
  • 4
  • 24
  • 44
  • "strange characters" out of a decryption routine means that it isn't working right. Any key will "decrypt" a string, but only one key will produce the original text. If you get garbage out,then you're doing something wrong. – Marc B Sep 29 '11 at 16:12

1 Answers1

3
  1. Why would you need to decode a password? Why not store it hashed?

  2. There are a few constraints with the size of the input string and the key size as well (explained in the online doc).

Here's a working example with Oracle 10.2.0.3:

SQL> VARIABLE v_in VARCHAR2(64);
SQL> VARIABLE v_enc VARCHAR2(64);
SQL> VARIABLE v_out VARCHAR2(64);
SQL> DECLARE
  2     l_key VARCHAR2(8) := rpad('my_key', 8, 'x'); -- 64-bit key
  3  BEGIN
  4     -- input size must be a multiple of 8 bytes
  5     :v_in               := '12345678';
  6     :v_enc := dbms_obfuscation_toolkit.desEncrypt(input_string => :v_in,
  7                                                   key_string => l_key);
  8     :v_out := dbms_obfuscation_toolkit.desDecrypt(input_string => :v_enc,
  9                                                   key_string => l_key);
 10  END;
 11  /

PL/SQL procedure successfully completed
v_in
---------
12345678
v_enc
---------
þæHI«Ó¹-
v_out
---------
12345678
Community
  • 1
  • 1
Vincent Malgrat
  • 66,725
  • 9
  • 119
  • 171