CertPath
)
and certificate revocation list (CRL) objects from their encodings.
For encodings consisting of multiple certificates, use
generateCertificates
when you want to
parse a collection of possibly unrelated certificates. Otherwise,
use generateCertPath
when you want to generate
a CertPath
(a certificate chain) and subsequently
validate it with a CertPathValidator
.
A certificate factory for X.509 must return certificates that are an
instance of java.security.cert.X509Certificate
, and CRLs
that are an instance of java.security.cert.X509CRL
.
The following example reads a file with Base64 encoded certificates,
which are each bounded at the beginning by -----BEGIN CERTIFICATE-----, and
bounded at the end by -----END CERTIFICATE-----. We convert the
FileInputStream
(which does not support mark
and reset
) to a BufferedInputStream
(which
supports those methods), so that each call to
generateCertificate
consumes only one certificate, and the
read position of the input stream is positioned to the next certificate in
the file:
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
while (bis.available() > 0) {
Certificate cert = cf.generateCertificate(bis);
System.out.println(cert.toString());
}
The following example parses a PKCS#7-formatted certificate reply stored in a file and extracts all the certificates from it:
FileInputStream fis = new FileInputStream(filename); CertificateFactory cf = CertificateFactory.getInstance("X.509"); Collection c = cf.generateCertificates(fis); Iterator i = c.iterator(); while (i.hasNext()) { Certificate cert = (Certificate)i.next(); System.out.println(cert); }
Every implementation of the Java platform is required to support the
following standard CertificateFactory
type:
X.509
CertPath
encodings:
PKCS7
PkiPath
Certificate
, X509Certificate
, CertPath
, CRL
, X509CRL
Modifier and Type | Field and Description |
---|---|
private final CertificateFactorySpi | |
private final Provider | |
private final String |
Access | Constructor and Description |
---|---|
protected | CertificateFactory(CertificateFactorySpi
the provider implementation. certFacSpi, Provider the provider. provider, String the certificate type. type)Creates a CertificateFactory object of the given type, and encapsulates the given provider implementation (SPI object) in it. |
Modifier and Type | Method and Description |
---|---|
public final Certificate | Returns: a certificate object initialized with the data from the input stream.an input stream with the certificate data. inStream)Generates a certificate object and initializes it with
the data read from the input stream |
public final Collection | Returns: a (possibly empty) collection view of java.security.cert.Certificate objects initialized with the data from the input stream.the input stream with the certificates. inStream)Returns a (possibly empty) collection view of the certificates read
from the given input stream |
public final CertPath | Returns: aCertPath initialized with the data from the
InputStream an inStream)InputStream containing the dataGenerates a |
public final CertPath | Returns: aCertPath initialized with the data from the
InputStream an inStream, String InputStream containing the datathe encoding used for the data encoding)Generates a |
public final CertPath | Returns: aCertPath initialized with the supplied list of
certificatesa certificates)List of Certificate sGenerates a |
public final CRL | Returns: a CRL object initialized with the data from the input stream.an input stream with the CRL data. inStream)Generates a certificate revocation list (CRL) object and initializes it
with the data read from the input stream |
public final Collection | Returns: a (possibly empty) collection view of java.security.cert.CRL objects initialized with the data from the input stream.the input stream with the CRLs. inStream)Returns a (possibly empty) collection view of the CRLs read
from the given input stream |
public final Iterator | Returns: anIterator over the names of the supported
CertPath encodings (as String s)Returns an iteration of the |
public static final CertificateFactory | Returns: a certificate factory object for the specified typethe name of the requested certificate type.
See the CertificateFactory section in the
Java Security Standard Algorithm Names Specification
for information about standard certificate types. type)Returns a certificate factory object that implements the specified certificate type. |
public static final CertificateFactory | Returns: a certificate factory object for the specified typethe certificate type.
See the CertificateFactory section in the
Java Security Standard Algorithm Names Specification
for information about standard certificate types. type, String the name of the provider. provider)Returns a certificate factory object for the specified certificate type. |
public static final CertificateFactory | Returns: a certificate factory object for the specified typethe certificate type.
See the CertificateFactory section in the
Java Security Standard Algorithm Names Specification
for information about standard certificate types. type, Provider the provider. provider)Returns a certificate factory object for the specified certificate type. |
public final Provider | Returns: the provider of this certificate factory.Returns the provider of this certificate factory. |
public final String | Returns: the name of the certificate type associated with this certificate factory.Returns the name of the certificate type associated with this certificate factory. |
certFacSpi | back to summary |
---|---|
private final CertificateFactorySpi certFacSpi |
provider | back to summary |
---|---|
private final Provider provider |
type | back to summary |
---|---|
private final String type |
CertificateFactory | back to summary |
---|---|
protected CertificateFactory(CertificateFactorySpi certFacSpi, Provider provider, String type) Creates a CertificateFactory object of the given type, and encapsulates the given provider implementation (SPI object) in it.
|
generateCertificate | back to summary |
---|---|
public final Certificate generateCertificate(InputStream inStream) throws CertificateException Generates a certificate object and initializes it with
the data read from the input stream In order to take advantage of the specialized certificate format
supported by this certificate factory,
the returned certificate object can be typecast to the corresponding
certificate class. For example, if this certificate
factory implements X.509 certificates, the returned certificate object
can be typecast to the In the case of a certificate factory for X.509 certificates, the
certificate provided in Note that if the given input stream does not support
|
generateCertificates | back to summary |
---|---|
public final Collection Returns a (possibly empty) collection view of the certificates read
from the given input stream In order to take advantage of the specialized certificate format
supported by this certificate factory, each element in
the returned collection view can be typecast to the corresponding
certificate class. For example, if this certificate
factory implements X.509 certificates, the elements in the returned
collection can be typecast to the In the case of a certificate factory for X.509 certificates,
Note that if the given input stream does not support
|
generateCertPath | back to summary |
---|---|
public final CertPath generateCertPath(InputStream inStream) throws CertificateException Generates a
|
generateCertPath | back to summary |
---|---|
public final CertPath generateCertPath(InputStream inStream, String encoding) throws CertificateException Generates a
|
generateCertPath | back to summary |
---|---|
public final CertPath generateCertPath(List<? extends Certificate> certificates) throws CertificateException Generates a
The certificates supplied must be of a type supported by the
|
generateCRL | back to summary |
---|---|
public final CRL generateCRL(InputStream inStream) throws CRLException Generates a certificate revocation list (CRL) object and initializes it
with the data read from the input stream In order to take advantage of the specialized CRL format
supported by this certificate factory,
the returned CRL object can be typecast to the corresponding
CRL class. For example, if this certificate
factory implements X.509 CRLs, the returned CRL object
can be typecast to the Note that if the given input stream does not support
|
generateCRLs | back to summary |
---|---|
public final Collection Returns a (possibly empty) collection view of the CRLs read
from the given input stream In order to take advantage of the specialized CRL format
supported by this certificate factory, each element in
the returned collection view can be typecast to the corresponding
CRL class. For example, if this certificate
factory implements X.509 CRLs, the elements in the returned
collection can be typecast to the In the case of a certificate factory for X.509 CRLs,
Note that if the given input stream does not support
|
getCertPathEncodings | back to summary |
---|---|
public final Iterator Returns an iteration of the
Attempts to modify the returned |
getInstance | back to summary |
---|---|
public static final CertificateFactory getInstance(String type) throws CertificateException Returns a certificate factory object that implements the specified certificate type. This method traverses the list of registered security Providers, starting with the most preferred Provider. A new CertificateFactory object encapsulating the CertificateFactorySpi implementation from the first Provider that supports the specified type is returned. Note that the list of registered providers may be retrieved via
the Implementation Note The JDK Reference Implementation additionally uses the
|
getInstance | back to summary |
---|---|
public static final CertificateFactory getInstance(String type, String provider) throws CertificateException, NoSuchProviderException Returns a certificate factory object for the specified certificate type. A new CertificateFactory object encapsulating the CertificateFactorySpi implementation from the specified provider is returned. The specified provider must be registered in the security provider list. Note that the list of registered providers may be retrieved via
the
|
getInstance | back to summary |
---|---|
public static final CertificateFactory getInstance(String type, Provider provider) throws CertificateException Returns a certificate factory object for the specified certificate type. A new CertificateFactory object encapsulating the CertificateFactorySpi implementation from the specified Provider object is returned. Note that the specified Provider object does not have to be registered in the provider list.
|
getProvider | back to summary |
---|---|
public final Provider getProvider() Returns the provider of this certificate factory.
|
getType | back to summary |
---|---|
public final String getType() Returns the name of the certificate type associated with this certificate factory.
|