Hello,
i wrote a Java app that uses SHA1 to compute hashes of users passwords witch are stored in a MySQL database. When i try to check PHP hashed user input against the stored value, they dont match.
Java class:
public class Hasher {
private String type;
public Hasher(String type) {
this.type = type;
}
public String encode(String pw) {
String hash = new String("");
try {
MessageDigest md = MessageDigest.getInstance(type);
byte[] textBytes = pw.getBytes("8859_1");
md.update(textBytes);
for (byte b : md.digest()) {
hash += Integer.toHexString(b & 0xff);
}
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
return hash;
}
}
Example:
String to hash: 1234
Result of class shown above: 7110eda4d09e62aa5e4a390b0a572acd2c220
Result of PHP sha1 function: 7110eda4d09e062aa5e4a390b0a572ac0d2c0220
obviously they dont match :) but why??