Oracle dbms_obfuscation_toolkit does not accept Null Value

Dear Experts,

I am using dbms_obfuscation_toolkit to encrypt and decrypt a password field in the Oracle Database. However, when I pass a null value the the encrypt function, it give errros:

ORA-28231: no data passed to obfuscation toolkit ORA-06512: at "SYS.DBMS_OBFUSCATION_TOOLKIT_FFI", line 0 ORA-06512: at "SYS.DBMS_OBFUSCATION_TOOLKIT", line 115 ORA-06512: at "User.ENCRYPT", line 7 ORA-06512: at "user.TG_USERLOGIN_ENC", line 2 ORA-04088: error during execution of trigger 'user.TG_USERLOGIN_ENC' System.Data.OracleClient

The following are the functions:

Encrypt function

( iValue in varchar2, iKey in varchar2 )
return varchar2
is
vEncrypted varchar2(4000);
begin
-- encrypt input string
dbms_obfuscation_toolkit.desencrypt (
input_string => iValue
, key_string => iKey
, encrypted_string => vEncrypted
);
return vEncrypted;
end;

Decrypt Function
( iValue in varchar2, iKey in varchar2 )
return varchar2
is
vDecrypted varchar2(4000);
begin
-- decrypt input string
dbms_obfuscation_toolkit.desdecrypt (
input_string => iValue
, key_string => iKey
, decrypted_string => vDecrypted
);
return vDecrypted;
end;

Trigger ( that fires before insert and update column)
begin
  :new.pwd := encrypt(rpad(:new.pwd, 32), 'facbldg14');
end;

What should I do in order to allow empty value?

Thanks

etalexit
etalexitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KurtRCommented:
don't use encryption for passwords! compute hash values and compare them to check for correct passwords.

example:
create or replace function calc_md5checksum(
  pv_Text in varchar2 -- your password
) return varchar2
is
  v_Text   varchar2(100) := 'S'||pv_Text||'E'; -- Add some "salt" to your password
  v_hash   varchar2(16);
begin

  v_hash := dbms_obfuscation_toolkit.md5(input_string => v_Text);
  return v_hash;

end calc_md5checksum;
/

let the user enter his password. compute the corresponding hash value and compare this computed hash value with the stored hash value for the correct password.
hashing is more secure for storing passwords. you cannot "decrypt" a hash value. oracle itself uses hash values for storing passwords (see dba_users).

by the way: the procedures of dbms_obfuscation_toolkit does not allow null-values as input strings. null cannot by encrypted.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
etalexitAuthor Commented:
If null cannot be encrypted, is there a way to do something like this?

In the encrypt/decrypt function:
If the input is null, simply return null. If not null, encrypt/decrypt the input.

How do i write such a function?

0
etalexitAuthor Commented:
Got it. I just have to add if-else statement.

For the encrypt function:
 ( iValue in varchar2, iKey in varchar2 )
return varchar2
is
vEncrypted varchar2(4000);
begin
-- encrypt input string
IF iValue IS NOT NULL THEN
  dbms_obfuscation_toolkit.desencrypt (
  input_string => iValue
  , key_string => iKey
  , encrypted_string => vEncrypted
  );
  return vEncrypted;
ELSE
  return Null;
END IF;
end;

Decrypt Function
 ( iValue in varchar2, iKey in varchar2 )
return varchar2
is
vDecrypted varchar2(4000);
begin
-- decrypt input string
if iValue is not null then
  dbms_obfuscation_toolkit.desdecrypt (
  input_string => iValue
  , key_string => iKey
  , decrypted_string => vDecrypted
  );
  return vDecrypted;
else
  return null;
end if;
end;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

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.