Code example for Mac

Methods: doFinal, init

0
     * @return hmac hashed bytes 
     */ 
    public byte[] calculateHmacSHA256(byte[] input, byte[] key) {
        byte[] output = null;
        try { 
            hmacSHA256.init(new SecretKeySpec(key, "HmacSHA256"));
            output = hmacSHA256.doFinal(input);
        } catch (InvalidKeyException e) {
            L.e("Invalid key", e);
        } 
        return output;
    } 
 
    /** 
     * Calculates an HMAC SHA256 hash using a set key length. 
     * 
     * @param input 
     * @param key 
     * @param length 
     * @return hmac hashed bytes 
     */