code: 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);
      }
    }
docs: Calculate and return a keyed hash message authentication code, HMAC, as specified in RFC2104
  using SHA256 as hash function.
  
  @param secret the secret used to authenticate
  @param data   the data to authenticate
  @param length the number of bytes from data to use when calculating the HMAC
  @return an HMAC code for the specified data and secret