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