public byte[] sign(Key key, byte[] data) throws GuacamoleException {

        try {

            // Init MAC for signing using secret key
            Mac mac = Mac.getInstance(SIGNATURE_MAC_ALGORITHM_NAME);
            mac.init(key);

            // Sign provided data
            return mac.doFinal(data);

        }

        // Rethrow all signature failures identically
        catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException e) {
            throw new GuacamoleServerException(e);
        }

    }
Signs the given arbitrary data using the provided key, returning the
resulting signature. If any error occurs during signing at all, a
GuacamoleException is thrown.

@param key
    The key to use to sign the provided data.

@param data
    The arbitrary data to sign.

@return
    The signature which results from signing the arbitrary data with the
    provided key.

@throws GuacamoleException
    If any error at all occurs during signing.
extensions/guacamole-auth-json/src/main/java/org/apache/guacamole/auth/json/CryptoService.java