Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / September 2007



Tip: Looking for answers? Try searching our database.

Hash value different than Java Hash value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NickIrons - 21 Sep 2007 18:31 GMT
If I hash "test" using Java, I get the following:
"e0ee22535e7b9035397d9425d9d533ca"

if i pass "test" to the coldfusion Hash function i get the following:
"098F6BCD4621D373CADE4E832627B4F6"

Can anybody tell me, why's that?
cf_dev2 - 21 Sep 2007 18:39 GMT
> If I hash "test" using Java, I get the following

What java code are you using?
NickIrons - 21 Sep 2007 18:42 GMT
private String hashDocument( String fileName )
  {
    byte[ ] fileBytes = new byte[ 256 ];
    int bytesRead = 0;
    String checksumString = "";

    try
    {
      MessageDigest digest = MessageDigest.getInstance( "MD5" );

      FileInputStream fis = new FileInputStream( tempPath + fileName );

      bytesRead = fis.read( fileBytes );

      while ( bytesRead > 0 )
      {
        bytesRead = fis.read( fileBytes );

        digest.update( fileBytes, 0, bytesRead );
      }

      byte[ ] checksum = digest.digest( );
      StringBuffer hexChecksum = new StringBuffer( );

      for ( int i = 0; i < checksum.length; i++ )
      {
        // Convert to a positive value between 0 and 255
        int intVal = (int) ( 0x000000ff & checksum[ i ] );

        hexChecksum.append( hexCodes[ intVal ] );
      }

      checksumString = hexChecksum.toString( );
    }
    catch ( Exception e )
    {
      log.warn( "Failed to calculate MD5 checksum for document: " + fileName +
".", e );
    }

    return checksumString;
  }
cf_dev2 - 21 Sep 2007 19:03 GMT
That's operating on the contents of a file, not a simple string like "test".
NickIrons - 21 Sep 2007 19:05 GMT
Correct, but what I'm saying is the Java hashing produces a different hash than
what the Coldfusion hash function does. I was using "test" as an example but
get the same kind of results using a file, which is what I'm actually trying to
do.
cf_dev2 - 21 Sep 2007 19:22 GMT
I can't see where all of the variables are defined. For example: hexCodes. Take
a look at  the public class MD5Util here.  The method accepts a string, but the
concept is the same.
http://site.gravatar.com/site/implement
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.