private static Mac getMacInstance(Mode mode, Key key)
            throws InvalidKeyException {

        try {
            Mac hmac = Mac.getInstance(mode.getAlgorithmName());
            hmac.init(key);
            return hmac;
        }
        catch (NoSuchAlgorithmException e) {
            throw new UnsupportedOperationException("Support for the HMAC "
                    + "algorithm required for TOTP in " + mode + " mode is "
                    + "missing.", e);
        }

    }
Returns a new Mac instance which produces message authentication codes
using the given secret key and the algorithm required by the given TOTP
mode.

@param mode
    The TOTP mode which dictates the HMAC algorithm to be used.

@param key
    The secret key to use to produce message authentication codes.

@return
    A new Mac instance which produces message authentication codes
    using the given secret key and the algorithm required by the given
    TOTP mode.

@throws InvalidKeyException
    If the provided key is invalid for the requested TOTP mode.
extensions/guacamole-auth-totp/src/main/java/org/apache/guacamole/totp/TOTPGenerator.java