I'm having a strange problem with converting a string to a byte array to hash it. Right now, my code is something like this:
String textToHash = "test";
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(textToHash.getBytes("UTF-8"));
hash = messageDigest.digest();
Even though the string is the same, on different runs, the byte array (generated from textToHash.getBytes("UTF-8")
) changes. Sometimes it will have one value, and other times it will change even though the string is static. Why is this happening and how can I make it reliably hash a string?
Thanks!
textToHash.getBytes
, it will sometimes return a different value. – Andrew Hassan Jan 24 at 16:26