Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Oracle dbms_obfuscation_toolkit does not accept Null Value

Posted on 2004-11-05
3
Medium Priority
?
2,916 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:etalexit
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
KurtR earned 2000 total points
ID: 12517213
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
 

Author Comment

by:etalexit
ID: 12522802
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
 

Author Comment

by:etalexit
ID: 12522888
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question