1 package org.cacert.gigi.util;
3 import java.security.MessageDigest;
4 import java.security.NoSuchAlgorithmException;
6 public class PasswordHash {
7 public static boolean verifyHash(String password, String hash) {
8 String newhash = sha1(password);
9 return newhash.equals(hash);
12 private static String sha1(String password) {
14 MessageDigest md = MessageDigest.getInstance("SHA1");
15 byte[] digest = md.digest(password.getBytes());
16 StringBuffer res = new StringBuffer(digest.length * 2);
17 for (int i = 0; i < digest.length; i++) {
18 res.append(Integer.toHexString((digest[i] & 0xF0) >> 4));
19 res.append(Integer.toHexString(digest[i] & 0xF));
21 return res.toString();
22 } catch (NoSuchAlgorithmException e) {
27 public static String hash(String password) {
28 return sha1(password);