Encryption in oracle

Hi Team,

Iam trying to encrypt the password from the user tables using the
DBMS_OBFUSCATION_TOOL_KIT.md5(input_STRING =>UTL_118N.STRING_TO_RAW('REC.PASSWORD'));

Iam using cursor for loop to process each record in the table , hence iam passing the field as rec.password.


But is generating the same value for all the records in the user table.

Any help is really appreciated.

USers tables

userid   username password
1             sam            sam0001
2             michael      michael002
sam_2012Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

SujithData ArchitectCommented:
You are passing a string "REC.PASSWORD" by enclosing it in single  quotes. Remove the single quote and

change it to -
DBMS_OBFUSCATION_TOOL_KIT.md5(input_STRING =>UTL_118N.STRING_TO_RAW(REC.PASSWORD));
0
slightwv (䄆 Netminder) Commented:
The values is generated when the cursor is executed not fetched.

You can simulate that with this simple test:
begin
for i in (select sysdate from dba_objects where rownum<6) loop
dbms_output.put_line(i.sysdate);
dbms_lock.sleep(1);
end loop;
end;
/

Open in new window


With the 1 second sleep, all the sysdate values return the same value.

You need to move the call to generate the passwords inside the loop.
0
SujithData ArchitectCommented:
@Sam you have named the package incorrectly in your code, see the below

SQL> select * from tbl1;

    USERID USERNAME             PASSWORD
---------- -------------------- --------------------
         1 sam                  sam0001
         2 michael              michael002

SQL> begin
  2      for rec in (select password from tbl1) loop
  3          dbms_output.put_line(DBMS_OBFUSCATION_TOOLKIT.md5(input_STRING =>UTL_I18N.STRING_TO_RAW(REC.PASSWORD)));
  4      end loop;
  5  end;
  6  /
+¤+Z|+++Z\+B+
+++J+??+Nx+A

PL/SQL procedure successfully completed.

Open in new window

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
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
Oracle Database

From novice to tech pro — start learning today.