Getting Oracle's MD5 to match PHP's MD5 Getting Oracle's MD5 to match PHP's MD5 oracle oracle

Getting Oracle's MD5 to match PHP's MD5


It returns raw bytes, you need to convert that into hex.

$x = unpack("H*", $row[0]); echo $x[1];


It appears that what's being printed from the Oracle query is the raw bytestream of the md5 checksum, mangled because most of those octets won't be ascii characters. Try converting it to hexadecimal first.


Create a function like the following:

create or replacefunction md5( input varchar2 ) return sys.dbms_obfuscation_toolkit.varchar2_checksum asbegin    return lower(rawtohex(utl_raw.cast_to_raw(sys.dbms_obfuscation_toolkit.md5( input_string => input ))));end;

and call it like this:

select md5('foobar') from dual;

it seems that "dbms_obfuscation_toolkit.md5" does not really return in raw format, hence the need to call "utl_raw.cast_to_raw". I could be wrong though, there should be a better explanation for this.