private static byte [ ] getAuthenticationCode ( byte [ ] secret , byte [ ] data , int length ) { try { SecretKey secretKey = new SecretKeySpec ( secret , MAC_ALGORITHM ) ; Mac mac = Mac . getInstance ( MAC_ALGORITHM ) ; mac . init ( secretKey ) ; mac . update ( data , 0 , length ) ; return mac . doFinal ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Calculate and return a keyed hash message authentication code HMAC as specified in RFC2104 using SHA256 as hash function .