package org.cacert.gigi.util;
+import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
* </ul>
*/
public static String verifyHash(String password, String hash) {
+ if (password == null || password.isEmpty()) {
+ return null;
+ }
if (hash.contains("$")) {
if (SCryptUtil.check(password, hash)) {
return hash;
}
}
- private static String sha1(String password) {
+ public static String sha1(String password) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
- byte[] digest = md.digest(password.getBytes());
+ byte[] digest = md.digest(password.getBytes("UTF-8"));
StringBuffer res = new StringBuffer(digest.length * 2);
for (int i = 0; i < digest.length; i++) {
res.append(Integer.toHexString((digest[i] & 0xF0) >> 4));
return res.toString();
} catch (NoSuchAlgorithmException e) {
throw new Error(e);
+ } catch (UnsupportedEncodingException e) {
+ throw new Error(e);
}
}