I'm trying to make a hash in php but I cant get the correct hash.
The java code is:
if (sPassword == null || sPassword.equals("")) {
return "empty:";
} else {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(sPassword.getBytes("UTF-8"));
byte[] res = md.digest();
return "sha1:" + StringUtils.byte2hex(res);
} catch (NoSuchAlgorithmException e) {
return "plain:" + sPassword;
} catch (UnsupportedEncodingException e) {
return "plain:" + sPassword;
}
}
Can somebody translate this to php?
For example if I put in Java the following pass: 123456789
, The hash is: sha1:625D7360E198F528978A4D061F3420923AF867C5
.