See {@link OpenSslX509KeyManagerFactory#newEngineBased(X509Certificate[], String)}.
552496
public static OpenSslX509KeyManagerFactory newKeyless(File chain)
            throws CertificateException, IOException,
            KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
        return newKeyless(SslContext.toX509Certificates(chain));
    }
114957
public static X509CertImpl toImpl(X509Certificate cert)
            throws CertificateException {
        if (cert instanceof X509CertImpl) {
            return (X509CertImpl)cert;
        } else {
            return X509Factory.intern(cert);
        }
    }
1044568
public static PhysicsEngine setPhysicsEngine(PhysicsEngine newEngine) {
		final PhysicsEngine oldEngine = engine;
		if (newEngine == null) {
			engine = new JavaPhysicsEngine();
		} else {
			engine = newEngine;
		}
		return oldEngine;
	}
488861
@Override
	public void engineSetKeyEntry(String s, Key key, char[] chars,
			Certificate[] certificates) throws KeyStoreException {

		if (!(key instanceof PrivateKey)) {
			throw new KeyStoreException("PrivateKey expected");
		}

		if (!(certificates instanceof X509Certificate[])) {
			throw new KeyStoreException(
					"Certificate chain of X509Certificate expected");
		}
		CredentialWrapper wrapper;
		X509Credential credential = new X509Credential((PrivateKey) key,
				(X509Certificate[]) certificates);
		if (credential.isEncryptedKey()) {
			wrapper = createCertKeyCredential(s, credential);
		} else {
			wrapper = createProxyCredential(s, credential);
		}
		storeWrapper(wrapper);
		this.aliasObjectMap.put(wrapper.getAlias(), wrapper);
	}
1145140
private X509Certificate loadX509FromPEMFile(String filename) {
        try {
            return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(FileReader.openStreamToFileFromClassPathOrPath(filename));
        } catch (Exception e) {
            throw new RuntimeException("Exception reading X509 from PEM file", e);
        }
    }
1224763
public static DatabaseProtocolFrontendEngine newInstance(final DatabaseType databaseType) {
        for (DatabaseProtocolFrontendEngine each : NewInstanceServiceLoader.newServiceInstances(DatabaseProtocolFrontendEngine.class)) {
            if (DatabaseType.valueFrom(each.getDatabaseType()) == databaseType) {
                return each;
            }
        }
        throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType));
    }
428766
public <S, D> TypeMap<S, D> create(S source, Class<S> sourceType, Class<D> destinationType,
      String typeMapName, InheritingConfiguration configuration, MappingEngineImpl engine) {
    synchronized (lock) {
      TypeMapImpl<S, D> typeMap = new TypeMapImpl<S, D>(sourceType, destinationType, typeMapName,
          configuration, engine);
      if (configuration.isImplicitMappingEnabled()
          && Types.mightContainsProperties(typeMap.getSourceType())
          && Types.mightContainsProperties(typeMap.getDestinationType()))
        ImplicitMappingBuilder.build(source, typeMap, config.typeMapStore, config.converterStore);
      typeMaps.put(TypePair.of(sourceType, destinationType, typeMapName), typeMap);
      return typeMap;
    }
  }
430196
@SuppressWarnings("unchecked")
  @Override
  public <T> T newInstance(Target<T> target) {
    Map<String, MethodHandler> nameToHandler = targetToHandlersByName.apply(target);
    Map<Method, MethodHandler> methodToHandler = new LinkedHashMap<Method, MethodHandler>();
    List<DefaultMethodHandler> defaultMethodHandlers = new LinkedList<DefaultMethodHandler>();

    for (Method method : target.type().getMethods()) {
      if (method.getDeclaringClass() == Object.class) {
        continue;
      } else if (Util.isDefault(method)) {
        DefaultMethodHandler handler = new DefaultMethodHandler(method);
        defaultMethodHandlers.add(handler);
        methodToHandler.put(method, handler);
      } else {
        methodToHandler.put(method, nameToHandler.get(Feign.configKey(target.type(), method)));
      }
    }
    InvocationHandler handler = factory.create(target, methodToHandler);
    T proxy = (T) Proxy.newProxyInstance(target.type().getClassLoader(),
        new Class<?>[] {target.type()}, handler);

    for (DefaultMethodHandler defaultMethodHandler : defaultMethodHandlers) {
      defaultMethodHandler.bindTo(proxy);
    }
    return proxy;
  }
388460
public static <K, V> KeyAffinityService<K> newKeyAffinityService(Cache<K, V> cache, Executor ex, KeyGenerator<K> keyGenerator, int keyBufferSize) {
      return newKeyAffinityService(cache, ex, keyGenerator, keyBufferSize, true);
   }
967179
static Codec<NamingMessage> createFullCodec(final IdentifierFactory factory) {
    final Map<Class<? extends NamingMessage>, Codec<? extends NamingMessage>> clazzToCodecMap
        = new HashMap<>();
    clazzToCodecMap.put(NamingLookupRequest.class, new NamingLookupRequestCodec(factory));
    clazzToCodecMap.put(NamingLookupResponse.class, new NamingLookupResponseCodec(factory));
    clazzToCodecMap.put(NamingRegisterRequest.class, new NamingRegisterRequestCodec(factory));
    clazzToCodecMap.put(NamingRegisterResponse.class,
        new NamingRegisterResponseCodec(new NamingRegisterRequestCodec(factory)));
    clazzToCodecMap.put(NamingUnregisterRequest.class, new NamingUnregisterRequestCodec(factory));
    final Codec<NamingMessage> codec = new MultiCodec<>(clazzToCodecMap);
    return codec;
  }
979258
public HsqlName newAutoName(String prefix, HsqlName schema,
                                HsqlName parent, int type) {

        HsqlName name = newAutoName(prefix, (String) null, schema, parent,
                                    type);

        return name;
    }
1331093
public static KeySpec newPBEKeySpec(final String privateKey)
	{
		if (privateKey == null)
		{
			return new PBEKeySpec(CompoundAlgorithm.PRIVATE_KEY.toCharArray());
		}
		return new PBEKeySpec(privateKey.toCharArray());
	}
78665
protected SslHandler newHandler(ByteBufAllocator alloc, boolean startTls, Executor executor) {
        return new SslHandler(newEngine(alloc), startTls, executor);
    }
239990
public static Builder newBuilder(String projectId, String datasetId) {
    return newBuilder(DatasetId.of(projectId, datasetId));
  }
145951
static SSLContext createSSLContext() {
    try {
      SSLContext sc = SSLContext.getInstance("SSL");
      TrustManager[] tm = {
          new X509TrustManager() {
            @SuppressLint("TrustAllX509TrustManager") @Override
            public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate,
                String paramString) {
            }

            @SuppressLint("TrustAllX509TrustManager") @Override
            public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate,
                String paramString) {
            }

            @Override public X509Certificate[] getAcceptedIssuers() {
              return new X509Certificate[] {};
            }
          }
      };
      sc.init(null, tm, new SecureRandom());
      return sc;
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
      e.printStackTrace();
    }

    return null;
  }
936484
private X509Certificate createCASignedCert(PublicKey publicKey, X509Certificate certificateAuthorityCert, PrivateKey certificateAuthorityPrivateKey, PublicKey certificateAuthorityPublicKey, String domain, String[] subjectAlternativeNameDomains, String[] subjectAlternativeNameIps) throws Exception {

        // signers name
        X500Name issuer = new X509CertificateHolder(certificateAuthorityCert.getEncoded()).getSubject();

        // subjects name - the same as we are self signed.
        X500Name subject = new X500Name("CN=" + domain + ", O=MockServer, L=London, ST=England, C=UK");

        // serial
        BigInteger serial = BigInteger.valueOf(new Random().nextInt(Integer.MAX_VALUE));

        // create the certificate - version 3
        X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(issuer, serial, NOT_BEFORE, NOT_AFTER, subject, publicKey);
        builder.addExtension(Extension.subjectKeyIdentifier, false, createSubjectKeyIdentifier(publicKey));
        builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(false));

        // subject alternative name
        List<ASN1Encodable> subjectAlternativeNames = new ArrayList<ASN1Encodable>();
        if (subjectAlternativeNameDomains != null) {
            subjectAlternativeNames.add(new GeneralName(GeneralName.dNSName, domain));
            for (String subjectAlternativeNameDomain : subjectAlternativeNameDomains) {
                subjectAlternativeNames.add(new GeneralName(GeneralName.dNSName, subjectAlternativeNameDomain));
            }
        }
        if (subjectAlternativeNameIps != null) {
            for (String subjectAlternativeNameIp : subjectAlternativeNameIps) {
                if (IPAddress.isValidIPv6WithNetmask(subjectAlternativeNameIp)
                    || IPAddress.isValidIPv6(subjectAlternativeNameIp)
                    || IPAddress.isValidIPv4WithNetmask(subjectAlternativeNameIp)
                    || IPAddress.isValidIPv4(subjectAlternativeNameIp)) {
                    subjectAlternativeNames.add(new GeneralName(GeneralName.iPAddress, subjectAlternativeNameIp));
                }
            }
        }
        if (subjectAlternativeNames.size() > 0) {
            DERSequence subjectAlternativeNamesExtension = new DERSequence(subjectAlternativeNames.toArray(new ASN1Encodable[subjectAlternativeNames.size()]));
            builder.addExtension(Extension.subjectAlternativeName, false, subjectAlternativeNamesExtension);
        }

        X509Certificate cert = signCertificate(builder, certificateAuthorityPrivateKey);

        cert.checkValidity(new Date());
        cert.verify(certificateAuthorityPublicKey);

        return cert;
    }
1063019
private static <T> T[] newEnumMap(Class<?> elementType,
                                      Function<SessionProtocol, T> factory,
                                      SessionProtocol... allowedProtocols) {
        @SuppressWarnings("unchecked")
        final T[] maps = (T[]) Array.newInstance(elementType, SessionProtocol.values().length);
        // Attempting to access the array with an unallowed protocol will trigger NPE,
        // which will help us find a bug.
        for (SessionProtocol p : allowedProtocols) {
            maps[p.ordinal()] = factory.apply(p);
        }
        return maps;
    }