class HashBasedMacTokenHandler {

    public String calculateHash(String key, String input) throws InvalidKeyException {
        Mac mac;
        try {
            mac = Mac.getInstance(ALGORITHM);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("Failed to initialise MAC object: " + e.getMessage(), e);
        }
        mac.init(getKey(key));
        return Hex.encodeHexString(mac.doFinal(getInputAsByteArray(input)));
    }

}