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

                // In OpenJDK 6, the SunPKCS11-NSS implementation of AES/ECB/NoPadding thinks
                // that it's AES/CTR/NoPadding during init() for some reason, which causes it
                // to throw an exception due to a lack of IV (required for CTR, prohibited for ECB).
                // We don't strongly care about checking this implementation, so just skip it.
                if (p.getName().equals("SunPKCS11-NSS")
                        && transformation.equals("AES/ECB/NoPadding")) {
                    continue;
                }

                // The SunJCE implementation of ChaCha20 only supports initializing with
                // ChaCha20ParameterSpec, introduced in Java 11.  For now, just skip testing it.
                if (transformation.equals("ChaCha20") && p.getName().equals("SunJCE")) {
                    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]);

                    // Initialize the IV, if there is one
                    AlgorithmParameters params;
                    if (iv.length > 0) {
                        params = AlgorithmParameters.getInstance(getBaseAlgorithm(transformation));
                        params.init(iv, "RAW");
                    } else {
                        params = null;
                    }

                    try {
                        for (CallPattern callPattern: CallPattern.values()) {
                            cipher.init(Cipher.ENCRYPT_MODE, key, params);
                            assertEquals("Provider " + p.getName()
                                        + ", algorithm " + transformation
                                        + " reported the wrong output size",
                                ciphertext.length, cipher.getOutputSize(plaintext.length));
                            byte[] encrypted = callCipher(
                                cipher, plaintext, ciphertext.length, callPattern);
                            assertArrayEquals(
                                "Provider " + p.getName() + ", algorithm " + transformation
                                    + ", CallPattern " + callPattern
                                    + " failed on encryption, data is " + Arrays.toString(line),
                                ciphertext, encrypted);

                            cipher.init(Cipher.DECRYPT_MODE, key, params);
                            byte[] decrypted;
                            try {
                                decrypted = callCipher(
                                    cipher, ciphertext, plaintext.length, callPattern);
                            } catch (GeneralSecurityException e) {
                                throw new GeneralSecurityException("Provider " + p.getName()
                                + ", algorithm " + transformation + ", CallPattern " + callPattern
                                + " failed on decryption, data is " + Arrays.toString(line), e);
                            }
                            assertArrayEquals(
                                "Provider " + p.getName() + ", algorithm " + transformation
                                    + ", CallPattern " + callPattern
                                    + " failed on decryption, data is " + Arrays.toString(line),
                                plaintext, decrypted);
                        }
                    } catch (InvalidKeyException e) {
                        // Some providers may not support raw SecretKeySpec keys, that's allowed
                    }
                }
            }
        }
    }
Calls an initialized cipher with different equivalent call patterns.
common/src/test/java/org/conscrypt/javax/crypto/CipherBasicsTest.java