Example usage for org.bouncycastle.jcajce.provider.asymmetric.x509 CertificateFactory engineGenerateCertificate

List of usage examples for org.bouncycastle.jcajce.provider.asymmetric.x509 CertificateFactory engineGenerateCertificate

Introduction

In this page you can find the example usage for org.bouncycastle.jcajce.provider.asymmetric.x509 CertificateFactory engineGenerateCertificate.

Prototype

public java.security.cert.Certificate engineGenerateCertificate(InputStream in) throws CertificateException 

Source Link

Document

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

Usage

From source file:org.codice.ddf.security.certificate.generator.PkiTools.java

License:Open Source License

/**
 * Given a PEM encoded X509 certificate, return an object representation of the certificate
 *
 * @param certString PEM encoded X509 certificate
 * @return instance of X509 certificate//  w  ww .ja v  a 2  s.co m
 */
public static X509Certificate pemToCertificate(String certString) {
    CertificateFactory cf = new CertificateFactory();
    ByteArrayInputStream in = new ByteArrayInputStream(PkiTools.pemToDer(certString));
    X509Certificate cert;
    try {
        cert = (X509Certificate) cf.engineGenerateCertificate(in);
    } catch (CertificateException e) {
        throw new CertificateGeneratorException("Cannot convert this PEM object to X509 certificate", e);
    }
    if (cert == null) {
        throw new CertificateGeneratorException("Cannot convert this PEM object to X509 certificate");
    }
    return cert;
}