private static OpenSSLKey fromKeyMaterial(PrivateKey key) throws InvalidKeyException {
        if (!"PKCS#8".equals(key.getFormat())) {
            return null;
        }
        byte[] encoded = key.getEncoded();
        if (encoded == null) {
            return null;
        }
        try {
            return new OpenSSLKey(NativeCrypto.EVP_parse_private_key(encoded));
        } catch (ParsingException e) {
            throw new InvalidKeyException(e);
        }
    }
Gets an {@code OpenSSLKey} instance initialized with the key material of the provided key.

@return instance or {@code null} if the {@code key} does not export its key material in a
        suitable format.
common/src/main/java/org/conscrypt/OpenSSLKey.java