I am trying to get a hash value for a string using MessageDigest in Java, but the value is different every time. When I run the program twice it will again have completely different answers.
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException nsae) {
}
md.update("string".getBytes());
byte[] digest = md.digest();
System.out.println(digest);
md.reset();
md.update("string".getBytes());
byte[] digest2 = md.digest();
System.out.println(digest2);
You are outputting the
byte[]object, not the byte array contents. Use