MessageDigest md = MessageDigest.getInstance(digest);
byte[] data = md.digest(provided.getBytes());
if (encoding == null || "hex".equalsIgnoreCase(encoding)) {
// Convert bytes to hex digits
byte[] hexData = new byte[data.length * 2];
HexTranslator ht = new HexTranslator();
ht.encode(data, 0, data.length, hexData, 0);
// Compare the digested provided password with the actual one
return real.equalsIgnoreCase(new String(hexData));
} else if ("base64".equalsIgnoreCase(encoding)) {
return real.equals(new String(Base64.encode(data)));
}