Tuesday, July 22, 2008

How to encrypt decrypt password in Oracle data table?

Programmers sometimes need to store user password and some other fields in database data table in encrypted format. There exists an easy way to do this. I have used in my database. In my system, I have a table called Users which contains fields: UserID, UserName, Password,and Email. I have encrypted the password field.

[While continuing the journey, you may also be interested in implementing object relational database features of Oracle illustrated for a simple ecommerce database.]

With this scenario, I get following issues to be solved.Encrypt input password before inserting into data table.Decrypt password before reading it.

For all these requirements I use two functions, one for encrypting password and another for decrypting password.

--create two function: one for encrypt--the other for decrypt:

FUNCTION encrypt( 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;/

FUNCTION decrypt( 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/

2 comments:

Anonymous said...

Really Impressive...

Anonymous said...

I have a question on the key used to decrypt the password. How to secure this key?

Post a Comment

Hope you liked this post. You can leave your message or you can put your valuable suggestions on this post here. Thanks for the sharing and cooperation!

Popular Posts

Recent Articles