public static String hash(String algorithm, String str) {
		StringBuilder ret = new StringBuilder();
		byte[] bytes = null;

		try {
			MessageDigest hash = MessageDigest.getInstance(algorithm);
			bytes = hash.digest(str.getBytes("UTF8"));
		} catch (Exception e) {
		}

		for (byte b : bytes) {
			ret.append(toHex(b));
		}

		return ret.toString();
	}