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?
 
SujithConnect With a Mentor Data 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
 
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
All Courses

From novice to tech pro — start learning today.