code: public static void loadKeyStoreFromCertificates(
        KeyStore keyStore, CertificateFactory certificateFactory, InputStream certificateStream)
        throws GeneralSecurityException {
      int i = 0;
      for (Certificate cert : certificateFactory.generateCertificates(certificateStream)) {
        keyStore.setCertificateEntry(String.valueOf(i), cert);
        i++;
      }
    }
docs: Loads a key store with certificates generated from the specified stream using {@link
  CertificateFactory#generateCertificates(InputStream)}.
  
  <p>For each certificate, {@link KeyStore#setCertificateEntry(String, Certificate)} is called
  with an alias that is the string form of incrementing non-negative integers starting with 0 (0,
  1, 2, 3, ...).
  
  <p>Example usage:
  
  <pre>
  KeyStore keyStore = SecurityUtils.getJavaKeyStore();
  SecurityUtils.loadKeyStoreFromCertificates(keyStore, SecurityUtils.getX509CertificateFactory(),
  new FileInputStream(pemFile));
  </pre>
  
  @param keyStore key store (for example {@link #getJavaKeyStore()})
  @param certificateFactory certificate factory (for example {@link
  #getX509CertificateFactory()})
  @param certificateStream certificate stream