Code example for Key

Methods: getAlgorithm

0
     * @param input the input over which to compute the MAC 
     * @return the computed MAC value 
     * @throws SecurityException thrown if the MAC computation results in an error 
     */ 
    public static byte[] signMAC(Key signingKey, String jcaAlgorithmID, byte[] input) throws SecurityException {
        log.debug("Computing MAC over input using key of type {} and JCA algorithm ID {}", signingKey.getAlgorithm(),
                jcaAlgorithmID);
 
        try { 
            Mac mac = Mac.getInstance(jcaAlgorithmID);
            mac.init(signingKey);
            mac.update(input);
            byte[] rawMAC = mac.doFinal();
            log.debug("Computed MAC: {}", new String(Hex.encode(rawMAC)));
            return rawMAC;
        } catch (GeneralSecurityException e) {
            log.error("Error during MAC generation", e);
            throw new SecurityException("Error during MAC generation", e);
        } 
    }