byte[] iv = contentEncryptionParts.getIv();
byte[] ciphertext = contentEncryptionParts.getCiphertext();
byte[] authenticationTag = contentEncryptionParts.getAuthenticationTag();
byte[] al = getAdditionalAuthenticatedDataLengthBytes(aad);
byte[] authenticationTagInput = ByteUtil.concat(aad, iv, ciphertext, al);
Key hmacKey = new HmacKey(ByteUtil.leftHalf(contentEncryptionKey));
Mac mac = MacUtil.getInitializedMac(getHmacJavaAlgorithm(), hmacKey);
byte[] calculatedAuthenticationTag = mac.doFinal(authenticationTagInput);
calculatedAuthenticationTag = ByteUtil.subArray(calculatedAuthenticationTag, 0, getTagTruncationLength()); // truncate it
boolean tagMatch = ByteUtil.secureEquals(authenticationTag, calculatedAuthenticationTag);
if (!tagMatch)