This discussion is archived
4 Replies Latest reply: Nov 21, 2012 11:11 AM by rp0428 RSS

MD5 HASH computed from DBMS_CRYPTO does not match .NET MD5

SatishKandi Guru
Currently Being Moderated
Oracle 10.2.0.5.0
Windows 2003 R2 Standard Edition 32 bit

Note: This probably is a question for Microsoft forums but I just wanted to seek inputs from this forum first.

Used following piece of code
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> SET SERVEROUT ON
SQL>
SQL> DECLARE
  2     sRAWString   RAW (32767) := UTL_RAW.CAST_TO_RAW ('1234567890');
  3  BEGIN
  4     DBMS_OUTPUT.put_line (SYS.DBMS_CRYPTO.HASH (sRAWString, SYS.DBMS_CRYPTO.HASH_MD5));
  5  END;
  6  /
E807F1FCF82D132F9BB018CA6738A19F

PL/SQL procedure successfully completed.
Wrote similar piece of code from .NET and the output does not match.
byte[] data = Encoding.ASCII.GetBytes("1234567890");

HashAlgorithm hA = MD5.Create() as HashAlgorithm;

data = hA.ComputeHash(data);

string ABC = Encoding.ASCII.GetString(data);
The byte array before the ComputeHash call is "23272412522484519471551762420210356161159".

Also the output that we receive from .NET cannot be displayed in our current Windows code page/font (square boxes and inverted question marks.

Could you please share any inputs in this regard?
  • 1. Re: MD5 HASH computed from DBMS_CRYPTO does not match .NET MD5
    rp0428 Guru
    Currently Being Moderated
    >
    Could you please share any inputs in this regard?
    It appears you are using the ASCII character set. The Crypto package always converts everything to AL32UTF8 before hashing so if the .NET character set is different the hash will likely be different.

    If you look at the spec header for the DBMS_CRYPTO package it shows this note:
    >
    -- Prior to encryption, hashing or keyed hashing, CLOB datatype is
    -- converted to AL32UTF8. This allows cryptographic data to be
    -- transferred and understood between databases with different
    -- character sets, across character set changes and between
    -- separate processes (for example, Java programs).
    --
    Modify your example to use AL32UTF8 (UTF-8 in Java) and the results should match.
    I answered this question last week for a Java user in this forum article - see the last reply for the Java code change that was made
    Re: MD5. DBMS_CRYPTO.Hash vs java.security.MessageDigest
  • 2. Re: MD5 HASH computed from DBMS_CRYPTO does not match .NET MD5
    SatishKandi Guru
    Currently Being Moderated
    Thanks for the perfect pointer.
  • 3. Re: MD5 HASH computed from DBMS_CRYPTO does not match .NET MD5
    975554 Newbie
    Currently Being Moderated
    Hello,

    I too have a problem where the MD5 value from DBMS_CRYPTO does not match a hash value from 3rd party MD5 tool (MD5 Checksum Calculator 0.0.5.58 or WinMD5Free v1.20). This occurs only on some of the XML files that I generate using DBMS_XSLPROCESSOR on a Linux OS. I added the both java functions(MD5 and MD5_UTF_8) to my package to what hash values they would produce but I get "ORA-29532: Java call terminated by uncaught Java exception: java.nio.BufferOverflowException " the XML is about 60mb. I copied MD5 and MD5_UTF_8 from the other post.

    l_hash raw(2000);
    l_checksum_md5 varchar2(2000);
    l_checksum_md5_utf_8 varchar2(2000);




    t_checksum := lower(RAWTOHEX(dbms_crypto.hash(src=>l_clob,typ=>dbms_crypto.hash_md5)));

    l_hash := get_md5_CLOB (l_clob);

    l_checksum_md5 := lower(rawtohex(l_hash));

    l_hash := get_md5_UTF_8_CLOB (l_clob);

    l_checksum_md5_UTF_8 := lower(rawtohex(l_hash));


    Please help,

    Thank You in advance
    Don
  • 4. Re: MD5 HASH computed from DBMS_CRYPTO does not match .NET MD5
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!

    Please do not HIJACK other users threads. This question has already been answered.

    If you have a question or problem open your own thread and post the particulars, including your 4 digit Oracle version.

    Do not respond or otherwise followup in this thread. Let it rest in peace. ;)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points