#1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594

    MD5 Hash Formatting


    I have a hash that was created with a PHP script uisng MD5. I need to feed that string to a Java app that uses the same input to create a hash that should match but doesn't. I think the problem is the format of the resulting hash string in Java. The PHP 'hash' function returns a hex representation of the hash string. I'm using MessageDigest to get the hash in my app which returns a binary string. I cannot find a way to get the hex representation of that string in order to do the compare. Is there a way to make MessageDigest return a hex representation? Alternatively, is there a way to convert the hex string to binary? Or in either case must I write my own method to do the conversion? TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    There are some class methods in Integer that might help.
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    MessageDigest to get the hash in my app which returns a binary string.
    What is a binary String? A String with characters either '0' or '1'?
    What method returns the binary string?
    The PHP 'hash' function returns a hex representation
    Is that in a String with only hexadecimal characters: '0' to 'f'?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,332
    Rep Power
    594
    Sorry for not updating this sooner. I have it working now. The problem was the way I was saving the compare string to a file. I base64 encoded it before writing it and now it works. Thanks.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo