@Test
    public void testAeadEncryption() throws Exception {
        TestUtils.assumeAEADAvailable();
        for (Provider p : Security.getProviders()) {
            for (Map.Entry<String, String> entry : AEAD_CIPHER_TO_TEST_DATA.entrySet()) {
                String transformation = entry.getKey();

                // On Android 10 and below, BC can return AES/GCM/NoPadding when asked for
                // AES/GCM-SIV/NoPadding. Android will never actually ship AES/GCM-SIV/NoPadding
                // in BC, so skip that combination.
                if (p.getName().equals("BC") && transformation.equals("AES/GCM-SIV/NoPadding")) {
                    continue;
                }

                Cipher cipher;
                try {
                    cipher = Cipher.getInstance(transformation, p);
                } catch (NoSuchAlgorithmException e) {
                    // This provider doesn't provide this algorithm, ignore it
                    continue;
                }

                List<String[]> data = TestUtils.readCsvResource(entry.getValue());
                for (String[] line : data) {
                    Key key = new SecretKeySpec(decodeHex(line[KEY_INDEX]),
                            getBaseAlgorithm(transformation));
                    byte[] iv = decodeHex(line[IV_INDEX]);
                    byte[] plaintext = decodeHex(line[PLAINTEXT_INDEX]);
                    byte[] ciphertext = decodeHex(line[CIPHERTEXT_INDEX]);
                    byte[] tag = decodeHex(line[TAG_INDEX]);
                    byte[] aad = decodeHex(line[AAD_INDEX]);

                    // Some ChaCha20 tests include truncated tags, which the Java API doesn't
                    // support.  Skip those tests.
                    if (transformation.startsWith("ChaCha20") && tag.length < 16) {
                        continue;
                    }

                    AlgorithmParameterSpec params;
                    if (transformation.contains("GCM")) {
                        params = new GCMParameterSpec(8 * tag.length, iv);
                    } else {
                        params = new IvParameterSpec(iv);
                    }

                    try {
                        arrayBasedAssessment(cipher, aad, tag, plaintext, ciphertext, key, params, transformation, p,
                                line);
                        bufferBasedAssessment(cipher, aad, tag, plaintext, ciphertext, key, params, transformation, p,
                                false, false);
                        bufferBasedAssessment(cipher, aad, tag, plaintext, ciphertext, key, params, transformation, p,
                                true, true);
                        bufferBasedAssessment(cipher, aad, tag, plaintext, ciphertext, key, params, transformation, p,
                                true, false);
                        bufferBasedAssessment(cipher, aad, tag, plaintext, ciphertext, key, params, transformation, p,
                                false, true);
                        sharedBufferBasedAssessment(cipher, aad, tag, plaintext, ciphertext, key, params,
                                transformation, p);
                    } catch (InvalidKeyException e) {
                        // Some providers may not support raw SecretKeySpec keys, that's allowed
                    } catch (InvalidAlgorithmParameterException e) {
                        // Some providers may not support all tag lengths or nonce lengths,
                        // that's allowed
                        if (e.getMessage().contains("IV must not be re-used")) {
                            throw new AssertionError("The same IV was used twice and therefore "
                                            + "some tests did not run."
                                            + "Provider = " + p.getName()
                                            + ", algorithm = " + transformation,
                                    e);
                        }
                    }
                }
            }
        }
    }
Calls an initialized cipher with different equivalent call patterns.
common/src/test/java/org/conscrypt/javax/crypto/CipherBasicsTest.java