title: Validating certificate chain in Java from truststore
body: <p>I have a certificate chain as der encoded byte[][] array to verify. I also have a truststore file. </p>
  
  <p>After I create X509Certificate[] from that byte array[][] and initializing trustmanager, how will I tell to TrustManager to verify that X509Certificate[]? What is the proper way to do it?</p>
  
  <p>Thanks.</p>
  
  <p>Sample code:</p>
  
  <pre><code>int certVerify(byte certChain[][])
  {
     CertificateFactory cf = CertificateFactory.getInstance("X509");
     X509Certificate certx[] = new X509Certificate[10];
     for(int i=0;i&lt;certChain.length;i++)
     {
       certx[i] = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certChain[i]));
     }
  
     KeyStore keyStore = KeyStore.getInstance("JKS");
     keyStore.load( new FileInputStream("cacerts.jks"),"123456".toCharArray());
  
     TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
     trustManagerFactory.init(keyStore);
  }
  </code></pre>