Package org.bouncycastle.openssl

Examples of org.bouncycastle.openssl.PEMWriter


  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);
View Full Code Here


    }
  }

  public static String serialize(KeyPair keyPair) throws IOException {
    StringWriter writer = new StringWriter();
    PEMWriter pemWriter = new PEMWriter(writer, BouncyCastleLoader.getName());
    try {
      pemWriter.writeObject(keyPair);
      pemWriter.flush();
      return writer.toString();
    } finally {
      IoUtils.safeClose(pemWriter);
    }
  }
View Full Code Here

          .info("======================================================");
      UGateUtil.PLAIN_LOGGER
          .info("CERTIFICATE PEM (to store in a certificate.pem file)");
      UGateUtil.PLAIN_LOGGER
          .info("======================================================");
      try (final PEMWriter pemWriter = new PEMWriter(new PrintWriter(
          System.out))) {
        pemWriter.writeObject(cert);
        pemWriter.flush();
        UGateUtil.PLAIN_LOGGER
            .info("======================================================");
        UGateUtil.PLAIN_LOGGER
            .info("PRIVATE KEY PEM (to store in a private.pem file)");
        UGateUtil.PLAIN_LOGGER
            .info("======================================================");
        pemWriter.writeObject(privateKey);
        pemWriter.flush();
      } catch (final Throwable t) {
        log.warn("Unable to dump certificate private PEM", t);
      }
    } catch (final Throwable t) {
      log.warn("Unable to dump certificate log", t);
View Full Code Here

                    PKCSObjectIdentifiers.signedData, sd));
        }
        else if (encoding.equalsIgnoreCase("PEM"))
        {
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();
            PEMWriter             pWrt = new PEMWriter(new OutputStreamWriter(bOut));

            try
            {
                for (int i = 0; i != certificates.size(); i++)
                {
                    pWrt.writeObject(certificates.get(i));
                }
           
                pWrt.close();
            }
            catch (Exception e)
            {
                throw new CertificateEncodingException("can't encode certificate for PEM encoded path");
            }
View Full Code Here

        }
        return null;
    }

    protected void doWriteKeyPair(KeyPair kp, OutputStream os) throws Exception {
        PEMWriter w = new PEMWriter(new OutputStreamWriter(os));
        w.writeObject(kp);
        w.flush();
    }
View Full Code Here

            try {
                fos = new FileOutputStream(PRIVATE_KEY_FILE_PATH);
                StringWriter stringWriter = new StringWriter();

                /* Write in PEM format (openssl support) */
                PEMWriter pemFormatWriter = new PEMWriter(stringWriter);
                pemFormatWriter.writeObject(keypair.getPrivate());
                pemFormatWriter.close();
                fos.write(stringWriter.toString().getBytes());
            } catch (IOException ioe) {
                throw ioe;
            } finally {
                if (fos != null) {
View Full Code Here

        StringWriter stringWriter = new StringWriter();
       
        /*
         * Write in PEM format (openssl support)
         */
        PEMWriter pemFormatWriter = new PEMWriter(stringWriter);
        pemFormatWriter.writeObject(keypair.getPrivate());
        pemFormatWriter.close();
        fos.write(stringWriter.toString().getBytes());
      } catch (IOException ioe) {
        throw ioe;
      } finally {
        if (fos != null) {
View Full Code Here

       
        //
        // PKCS7
        //
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        PEMWriter             pWrt = new PEMWriter(new OutputStreamWriter(bOut));
       
        pWrt.writeObject(d);
       
        pWrt.close();
       
        pemRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())));
        d = (ContentInfo)pemRd.readObject();   
       
        if (!d.getContentType().equals(CMSObjectIdentifiers.envelopedData))
View Full Code Here

        KeyPair pair)
        throws IOException
    {
        PEMReader pemRd;
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        PEMWriter             pWrt = new PEMWriter(new OutputStreamWriter(bOut));
       
        pWrt.writeObject(pair.getPublic());
       
        pWrt.close();

        pemRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())));
       
        PublicKey k = (PublicKey)pemRd.readObject();
        if (!k.equals(pair.getPublic()))
        {
            fail("Failed public key read: " + name);
        }
       
        bOut = new ByteArrayOutputStream();
        pWrt = new PEMWriter(new OutputStreamWriter(bOut));
       
        pWrt.writeObject(pair.getPrivate());
       
        pWrt.close();
       
        pemRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())));
       
        KeyPair kPair = (KeyPair)pemRd.readObject();
        if (!kPair.getPrivate().equals(pair.getPrivate()))
View Full Code Here

                                            String intermediateCertFileName = intermediateCertKeyName + ".pem";

                                            if (! SSL.isSslCertKeyPresent(_netscalerService, intermediateCertKeyName)) {
                                                byte[] certData= intermediateCert.getEncoded();
                                                StringWriter textWriter = new StringWriter();
                                                PEMWriter pemWriter = new PEMWriter(textWriter);
                                                pemWriter.writeObject(intermediateCert);
                                                pemWriter.flush();

                                                SSL.uploadCert(_ip, _username, _password, intermediateCertFileName, textWriter.toString().getBytes());
                                                SSL.createSslCertKey(_netscalerService, intermediateCertFileName, null, intermediateCertKeyName, null);
                                            }
View Full Code Here

TOP

Related Classes of org.bouncycastle.openssl.PEMWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.