private void test_KeyWithAllKeyFactories(Key k) throws Exception {
        byte[] encoded = k.getEncoded();

        String keyAlgo = k.getAlgorithm();
        for (Provider p : Security.getProviders()) {
            Set<Provider.Service> services = p.getServices();
            for (Provider.Service service : services) {
                if (!"KeyFactory".equals(service.getType())) {
                    continue;
                }
                if (!service.getAlgorithm().equals(keyAlgo)) {
                    continue;
                }
                if (p.getName().equalsIgnoreCase("AndroidKeyStore")) {
                    // AndroidKeyStore only works with its own keys
                    continue;
                }
                if ("EC".equals(k.getAlgorithm())
                        && "SunPKCS11-NSS".equalsIgnoreCase(p.getName())) {
                    // SunPKCS11 doesn't support some of the named curves that we expect, so it
                    // fails.  Skip testing that combination.
                    continue;
                }
                if ("DH".equals(k.getAlgorithm())
                        && "SunPKCS11-NSS".equalsIgnoreCase(p.getName())) {
                    // SunPKCS11 omits the privateValueLength field from the DHParameter
                    // structure in its encoded keys, unlike every other provider seen,
                    // so ignore it.
                    continue;
                }
                if ("XDH".equals(k.getAlgorithm())
                        && "SunEC".equalsIgnoreCase(p.getName())
                        && "11".equals(System.getProperty("java.specification.version"))) {
                    // SunEC in OpenJDK 11 has a bug where the format specified in RFC 8410
                    // Section 7. It uses a single OCTET STRING to represent the key instead
                    // of an OCTET STRING inside of an OCTET STRING as defined in the RFC:
                    // ("For the keys defined in this document, the private key is always an
                    //   opaque byte sequence.  The ASN.1 type CurvePrivateKey is defined in
                    //   this document to hold the byte sequence.  Thus, when encoding a
                    //   OneAsymmetricKey object, the private key is wrapped in a
                    //   CurvePrivateKey object and wrapped by the OCTET STRING of the
                    //   "privateKey" field.")
                    continue;
                }

                if ("PKCS#8".equals(k.getFormat())) {
                    PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(encoded);
                    KeyFactory kf = KeyFactory.getInstance(k.getAlgorithm(), p);
                    PrivateKey privKey = kf.generatePrivate(spec);
                    assertNotNull(k.getAlgorithm() + ", provider=" + p.getName(), privKey);

                    /*
                     * EC keys are unique because they can have explicit parameters or a curve
                     * name. Check them specially so this test can continue to function.
                     */
                    if (k instanceof ECPrivateKey) {
                        assertECPrivateKeyEquals((ECPrivateKey) k, (ECPrivateKey) privKey);
                    } else {
                        assertEquals(k.getAlgorithm() + ", provider=" + p.getName(),
                                TestUtils.encodeBase64(encoded),
                                TestUtils.encodeBase64(privKey.getEncoded()));
                    }
                } else if ("X.509".equals(k.getFormat())) {
                    X509EncodedKeySpec spec = new X509EncodedKeySpec(encoded);
                    KeyFactory kf = KeyFactory.getInstance(k.getAlgorithm(), p);
                    PublicKey pubKey = kf.generatePublic(spec);
                    assertNotNull(pubKey);
                    assertEquals(k.getAlgorithm() + ", provider=" + p.getName(),
                            TestUtils.encodeBase64(encoded),
                            TestUtils.encodeBase64(pubKey.getEncoded()));
                }
            }
        }
    }
Elliptic Curve Crypto named curves that should be supported.
common/src/test/java/org/conscrypt/java/security/KeyPairGeneratorTest.java