views:

49

answers:

2

Hi everybody.

when using oracle forms to generate md5 hash, i get result that is different from the result given by tomcat.

when using tomcat digest, i get:

C:\apache-tomcat-6.0.26\bin>digest -a md5 mypass
mypass:a029d0df84eb5549c641e04a9ef389e5

while using oracle forms, i get:

a029d0dfbfeb5549c641e04abff3bfe5

this is the code:

Declare
    v_checksum varchar2( 32 );
    v_hex_value varchar2( 32 );
begin
    v_checksum := SYS.DBMS_OBFUSCATION_TOOLKIT.MD5( input_string => 'mypass' );


    SELECT  LOWER( RAWTOHEX( v_checksum ) ) 
    INTO    v_hex_value
    FROM    dual;

    :res := v_hex_value;
end; 

why aren't they giving the same result ? is there something wrong with my code ?

A: 

Your code seems correct

I also get a029d0df84eb5549c641e04a9ef389e5 here http://md5hashgenerator.com/index.php

and also in sql server I get the same

SELECT CONVERT(VARCHAR(32),HashBytes('MD5', 'mypass'),2)
SQLMenace
+1  A: 

Hi mohamida,

which version of Oracle are you running ? Your code gives the good answer on 10.2.0.3.0:

SQL> VARIABLE res VARCHAR2(32);
SQL> Declare
  2      v_checksum varchar2( 32 );
  3      v_hex_value varchar2( 32 );
  4  begin
  5      v_checksum:=SYS.DBMS_OBFUSCATION_TOOLKIT.MD5(input_string=>'mypass');
  6  
  7  
  8      SELECT  LOWER( RAWTOHEX( v_checksum ) )
  9      INTO    v_hex_value
 10      FROM    dual;
 11  
 12      :res := v_hex_value;
 13  end;
 14  /

PL/SQL procedure successfully completed
res
---------
a029d0df84eb5549c641e04a9ef389e5

Also I tried the other MD5 functions and they give the same answer:

SQL> DECLARE
  2     l_input RAW(16) := utl_raw.cast_to_raw('mypass');
  3  BEGIN
  4     :res:=lower(rawtohex(dbms_obfuscation_toolkit.md5(input=>l_input)));
  5  END;
  6  /

PL/SQL procedure successfully completed
res
---------
a029d0df84eb5549c641e04a9ef389e5
Vincent Malgrat
your second method worked fine for me. i'm using oracle 10.2.0.1.0.i don't know why i'm having such differences between the 2 methods !!
mohamida
@mohamida: you're applying the `rawtohex` function to a string (VARCHAR2), I'm not sure this is the appropriate usage (it should be applied to a RAW) -- maybe this is why you're seeing a difference.
Vincent Malgrat