@Test
    public void testAES_keyConstrained() throws Exception {
        Provider[] providers = Security.getProviders();
        for (Provider p : providers) {
            if (isBuggyProvider(p.getName())) {
                continue;
            }
            for (Provider.Service s : p.getServices()) {
                if (s.getType().equals("Cipher")) {
                    if (s.getAlgorithm().startsWith("AES_128/")) {
                        Cipher c = Cipher.getInstance(s.getAlgorithm(), p);
                        assertTrue(s.getAlgorithm(), checkAES_keyConstraint(c, 128));
                        assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 192));
                        assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 256));
                    } else if (s.getAlgorithm().startsWith("AES_256/")) {
                        Cipher c = Cipher.getInstance(s.getAlgorithm(), p);
                        assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 128));
                        assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 192));
                        assertTrue(s.getAlgorithm(), checkAES_keyConstraint(c, 256));
                    }
                }
            }
        }
    }
Helper for testing that Cipher.unwrap() throws IllegalStateException when
initialized in modes other than UNWRAP.
common/src/test/java/org/conscrypt/javax/crypto/CipherTest.java