Example usage for org.bouncycastle.openssl.jcajce JcaPEMWriter JcaPEMWriter

List of usage examples for org.bouncycastle.openssl.jcajce JcaPEMWriter JcaPEMWriter

Introduction

In this page you can find the example usage for org.bouncycastle.openssl.jcajce JcaPEMWriter JcaPEMWriter.

Prototype

public JcaPEMWriter(Writer out) 

Source Link

Document

Base constructor.

Usage

From source file:org.sonatype.nexus.ssl.CertificateUtil.java

License:Open Source License

/**
 * Serialize a certificate into a PEM formatted String.
 *
 * @param certificate the certificate to be serialized.
 * @return the certificate in PEM format
 * @throws IOException thrown if the certificate cannot be converted into the PEM format.
 *//*from   w  w  w.j a v a  2 s .co m*/
public static String serializeCertificateInPEM(final Certificate certificate) throws IOException {
    StringWriter buff = new StringWriter();
    try (JcaPEMWriter writer = new JcaPEMWriter(buff)) {
        writer.writeObject(certificate);
    }
    return buff.toString();
}

From source file:org.xdi.oxauth.model.crypto.Certificate.java

License:MIT License

@Override
public String toString() {
    try {/*from  ww w  .j  a  v  a  2  s .c  om*/
        StringWriter stringWriter = new StringWriter();
        JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter);
        try {
            pemWriter.writeObject(x509Certificate);
            pemWriter.flush();
            return stringWriter.toString();
        } finally {
            pemWriter.close();
        }
    } catch (IOException e) {
        return StringUtils.EMPTY_STRING;
    } catch (Exception e) {
        return StringUtils.EMPTY_STRING;
    }
}