Search in sources :

Example 6 with PEMWriter

use of org.bouncycastle.openssl.PEMWriter in project platformlayer by platformlayer.

the class CertificateUtils method toPem.

public static String toPem(Iterable<X509Certificate> certs) {
    try {
        StringWriter stringWriter = new StringWriter();
        PEMWriter writer = new PEMWriter(stringWriter, BouncyCastleLoader.getName());
        for (X509Certificate cert : certs) {
            writer.writeObject(cert);
        }
        writer.close();
        String s = stringWriter.toString();
        return s;
    } catch (IOException e) {
        throw new IllegalArgumentException("Error serializing certificates", e);
    }
}
Also used : StringWriter(java.io.StringWriter) PEMWriter(org.bouncycastle.openssl.PEMWriter) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate)

Example 7 with PEMWriter

use of org.bouncycastle.openssl.PEMWriter in project XobotOS by xamarin.

the class Credentials method convertToPem.

/**
     * Convert objects to a PEM format, which is used for
     * CA_CERTIFICATE, USER_CERTIFICATE, and USER_PRIVATE_KEY
     * entries.
     */
public static byte[] convertToPem(Object... objects) throws IOException {
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(bao, Charsets.US_ASCII);
    PEMWriter pw = new PEMWriter(writer);
    for (Object o : objects) {
        pw.writeObject(o);
    }
    pw.close();
    return bao.toByteArray();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) PEMWriter(org.bouncycastle.openssl.PEMWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PEMWriter(org.bouncycastle.openssl.PEMWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 8 with PEMWriter

use of org.bouncycastle.openssl.PEMWriter in project MonjaDB by Kanatoko.

the class MBCUtil method toPem.

//--------------------------------------------------------------------------------
public static String toPem(X509Certificate cert) {
    ByteArrayOutputStream bo = null;
    try {
        bo = new ByteArrayOutputStream();
        PEMWriter writer = new PEMWriter(new OutputStreamWriter(bo));
        writer.writeObject(cert);
        writer.flush();
        writer.close();
        byte[] _data = bo.toByteArray();
        String pemStr = new String(_data);
        return pemStr;
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    } finally {
        MStreamUtil.closeStream(bo);
    }
}
Also used : PEMWriter(org.bouncycastle.openssl.PEMWriter) CertificateException(java.security.cert.CertificateException)

Example 9 with PEMWriter

use of org.bouncycastle.openssl.PEMWriter in project OpenAttestation by OpenAttestation.

the class TAHelper method createRSAKeyFile.

private void createRSAKeyFile(String sessionId) throws KeyStoreException, IOException, NoSuchAlgorithmException, javax.security.cert.CertificateException, java.security.cert.CertificateException {
    X509Certificate cert = certFromFile(aikverifyhome + File.separator + getCertFileName(sessionId));
    FileWriter fw = new FileWriter(aikverifyhome + File.separator + getRSAPubkeyFileName(sessionId));
    PEMWriter pemWriter = new PEMWriter(fw);
    pemWriter.writeObject(cert.getPublicKey());
    pemWriter.flush();
    fw.flush();
    pemWriter.close();
    fw.close();
}
Also used : PEMWriter(org.bouncycastle.openssl.PEMWriter) X509Certificate(java.security.cert.X509Certificate)

Aggregations

PEMWriter (org.bouncycastle.openssl.PEMWriter)9 IOException (java.io.IOException)4 StringWriter (java.io.StringWriter)3 X509Certificate (java.security.cert.X509Certificate)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 KeyPair (java.security.KeyPair)2 KeyPairGenerator (java.security.KeyPairGenerator)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Writer (java.io.Writer)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SecureRandom (java.security.SecureRandom)1 SignatureException (java.security.SignatureException)1 CertPathBuilderException (java.security.cert.CertPathBuilderException)1 CertificateException (java.security.cert.CertificateException)1 Date (java.util.Date)1