With Java, I am converting a String value to a hash using SHA1 on a MessageDigest instance. I am at the point where I have created a hash object:
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] hash = md.digest(password.getBytes("UTF-8"));
The part I do not understand is what b & 0xff means in the following code:
StringBuilder sb = new StringBuilder(2*hash.length);
for(byte b : hash) {
sb.append(String.format("%02x", b & 0xff));
}
I know that %02x means to specify a format where there are two characters using hexadecimal, but I've no idea what the second parameter is, what it does to each byte or what it means. A simple explanation would be great! :-)