Udostępnij za pośrednictwem


CertificateFactory Class

Definition

This class defines the functionality of a certificate factory, which is used to generate certificate, certification path (CertPath) and certificate revocation list (CRL) objects from their encodings.

[Android.Runtime.Register("java/security/cert/CertificateFactory", DoNotGenerateAcw=true)]
public class CertificateFactory : Java.Lang.Object
[<Android.Runtime.Register("java/security/cert/CertificateFactory", DoNotGenerateAcw=true)>]
type CertificateFactory = class
    inherit Object
Inheritance
CertificateFactory
Attributes

Remarks

This class defines the functionality of a certificate factory, which is used to generate certificate, certification path (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:

{@code
            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);
            }

Android provides the following CertificateFactory types: <table> <thead> <tr> <th>Algorithm</th> <th>Supported API Levels</th> </tr> </thead> <tbody> <tr> <td>X.509</td> <td>1+</td> </tr> </tbody> </table> and the following CertPath encodings: <table> <thead> <tr> <th>Name</th> <th>Supported (API Levels)</th> </tr> </thead> <tbody> <tr> <td>PKCS7</td> <td>1+</td> </tr> <tr> <td>PkiPath</td> <td>1+</td> </tr> </tbody> </table>

The type and encodings are described in the CertificateFactory section and the CertPath Encodings section of the Java Cryptography Architecture Standard Algorithm Name Documentation.

Added in 1.2.

Java documentation for java.security.cert.CertificateFactory.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

CertificateFactory(CertificateFactorySpi, Provider, String)

Creates a CertificateFactory object of the given type, and encapsulates the given provider implementation (SPI object) in it.

CertificateFactory(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

CertPathEncodings

Returns an iteration of the CertPath encodings supported by this certificate factory, with the default encoding first.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
Provider

Returns the provider of this certificate factory.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Type

Returns the name of the certificate type associated with this certificate factory.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GenerateCertificate(Stream)

Generates a certificate object and initializes it with the data read from the input stream inStream.

GenerateCertificateAsync(Stream)
GenerateCertificates(Stream)

Returns a (possibly empty) collection view of the certificates read from the given input stream inStream.

GenerateCertificatesAsync(Stream)
GenerateCertPath(IList<Certificate>)

Generates a CertPath object and initializes it with a List of Certificates.

GenerateCertPath(Stream, String)

Generates a CertPath object and initializes it with the data read from the InputStream inStream.

GenerateCertPath(Stream)

Generates a CertPath object and initializes it with the data read from the InputStream inStream.

GenerateCertPathAsync(IList<Certificate>)
GenerateCertPathAsync(Stream, String)
GenerateCertPathAsync(Stream)
GenerateCRL(Stream)

Generates a certificate revocation list (CRL) object and initializes it with the data read from the input stream inStream.

GenerateCRLAsync(Stream)
GenerateCRLs(Stream)

Returns a (possibly empty) collection view of the CRLs read from the given input stream inStream.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetInstance(String, Provider)

Returns a certificate factory object for the specified certificate type.

GetInstance(String, String)

Returns a certificate factory object for the specified certificate type.

GetInstance(String)

Returns a certificate factory object that implements the specified certificate type.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to