comparing MessageDigest, MD5, results
Posted on 2006-04-15
I am new to java security and I have been trying to get two message digests to output the same results for the same input string. Here is sample of the code I am using.
byte tester1 = test1.getBytes();
MessageDigest sign1 = MessageDigest.getInstance("MD5");
MessageDigest sign2 = MessageDigest.getInstance("MD5");
byte result1 = sign1.digest(tester1);
byte result2 = sign2.digest(tester1);
boolean equal = result1.equals(result2);
System.out.println("The hahes are equal is: " + equal);
System.out.println(result1.toString() + "\n" + result2.toString());
The output of this is that the byte arrays are never equal. Shouldn't MessageDigest.digest(byte b) always return the same array for the same input? Do I misunderstand what MessageDigest does? I have to hash encode a string to be compared for equality later. Thanks for your help.