48 * <code>generateCertificates</code> when you want to 49 * parse a collection of possibly unrelated certificates. Otherwise, 50 * use <code>generateCertPath</code> when you want to generate 51 * a <code>CertPath</code> (a certificate chain) and subsequently 52 * validate it with a <code>CertPathValidator</code>. 53 * 54 * <p>A certificate factory for X.509 must return certificates that are an 55 * instance of <code>java.security.cert.X509Certificate</code>, and CRLs 56 * that are an instance of <code>java.security.cert.X509CRL</code>. 57 * 58 * <p>The following example reads a file with Base64 encoded certificates, 59 * which are each bounded at the beginning by -----BEGIN CERTIFICATE-----, and 60 * bounded at the end by -----END CERTIFICATE-----. We convert the 61 * <code>FileInputStream</code> (which does not support <code>mark</code> 62 * and <code>reset</code>) to a <code>BufferedInputStream</code> (which 63 * supports those methods), so that each call to 64 * <code>generateCertificate</code> consumes only one certificate, and the 65 * read position of the input stream is positioned to the next certificate in 66 * the file:<p> 67 * 68 * <pre> 69 * FileInputStream fis = new FileInputStream(filename); 70 * BufferedInputStream bis = new BufferedInputStream(fis); 71 * 72 * CertificateFactory cf = CertificateFactory.getInstance("X.509"); 73 * 74 * while (bis.available() > 0) { 75 * Certificate cert = cf.generateCertificate(bis); 76 * System.out.println(cert.toString()); 77 * } 78 * </pre> 79 * 80 * <p>The following example parses a PKCS#7-formatted certificate reply stored 81 * in a file and extracts all the certificates from it:<p> 82 * 83 * <pre> 84 * FileInputStream fis = new FileInputStream(filename); 85 * CertificateFactory cf = CertificateFactory.getInstance("X.509"); 86 * Collection c = cf.generateCertificates(fis); 87 * Iterator i = c.iterator(); 88 * while (i.hasNext()) { 89 * Certificate cert = (Certificate)i.next(); 90 * System.out.println(cert); 91 * } 92 * </pre> 93 * 94 * <p> Every implementation of the Java platform is required to support the 95 * following standard <code>CertificateFactory</code> type: 96 * <ul> 97 * <li><tt>X.509</tt></li> 98 * </ul> | 48 * <code>generateCertificates</code> when you want to 49 * parse a collection of possibly unrelated certificates. Otherwise, 50 * use <code>generateCertPath</code> when you want to generate 51 * a <code>CertPath</code> (a certificate chain) and subsequently 52 * validate it with a <code>CertPathValidator</code>. 53 * 54 * <p>A certificate factory for X.509 must return certificates that are an 55 * instance of <code>java.security.cert.X509Certificate</code>, and CRLs 56 * that are an instance of <code>java.security.cert.X509CRL</code>. 57 * 58 * <p>The following example reads a file with Base64 encoded certificates, 59 * which are each bounded at the beginning by -----BEGIN CERTIFICATE-----, and 60 * bounded at the end by -----END CERTIFICATE-----. We convert the 61 * <code>FileInputStream</code> (which does not support <code>mark</code> 62 * and <code>reset</code>) to a <code>BufferedInputStream</code> (which 63 * supports those methods), so that each call to 64 * <code>generateCertificate</code> consumes only one certificate, and the 65 * read position of the input stream is positioned to the next certificate in 66 * the file:<p> 67 * 68 * <pre>{@code 69 * FileInputStream fis = new FileInputStream(filename); 70 * BufferedInputStream bis = new BufferedInputStream(fis); 71 * 72 * CertificateFactory cf = CertificateFactory.getInstance("X.509"); 73 * 74 * while (bis.available() > 0) { 75 * Certificate cert = cf.generateCertificate(bis); 76 * System.out.println(cert.toString()); 77 * } 78 * }</pre> 79 * 80 * <p>The following example parses a PKCS#7-formatted certificate reply stored 81 * in a file and extracts all the certificates from it:<p> 82 * 83 * <pre> 84 * FileInputStream fis = new FileInputStream(filename); 85 * CertificateFactory cf = CertificateFactory.getInstance("X.509"); 86 * Collection c = cf.generateCertificates(fis); 87 * Iterator i = c.iterator(); 88 * while (i.hasNext()) { 89 * Certificate cert = (Certificate)i.next(); 90 * System.out.println(cert); 91 * } 92 * </pre> 93 * 94 * <p> Every implementation of the Java platform is required to support the 95 * following standard <code>CertificateFactory</code> type: 96 * <ul> 97 * <li><tt>X.509</tt></li> 98 * </ul> |