List of usage examples for org.bouncycastle.openssl.jcajce JcaPEMWriter JcaPEMWriter
public JcaPEMWriter(Writer out)
From source file:org.hyperledger.fabric.sdk.security.CryptoPrimitives.java
License:Open Source License
/** * certificationRequestToPEM - Convert a PKCS10CertificationRequest to PEM * format.//from w w w . ja v a2s .c o m * * @param csr The Certificate to convert * @return An equivalent PEM format certificate. * @throws IOException */ public String certificationRequestToPEM(PKCS10CertificationRequest csr) throws IOException { PemObject pemCSR = new PemObject("CERTIFICATE REQUEST", csr.getEncoded()); StringWriter str = new StringWriter(); JcaPEMWriter pemWriter = new JcaPEMWriter(str); pemWriter.writeObject(pemCSR); pemWriter.close(); str.close(); return str.toString(); }
From source file:org.jboss.as.quickstarts.helloworld.HelloWorldServlet.java
License:Apache License
public static String getPemFromCertificate(X509Certificate certificate) { if (certificate != null) { StringWriter writer = new StringWriter(); JcaPEMWriter pemWriter = new JcaPEMWriter(writer); try {/*from ww w . j a v a 2 s. c o m*/ pemWriter.writeObject(certificate); pemWriter.flush(); pemWriter.close(); } catch (IOException e) { throw new RuntimeException(e); } String s = writer.toString(); return removeBeginEnd(s); } else { return null; } }
From source file:org.littleshoot.proxy.mitm.BouncyCastleSslEngineSource.java
License:Apache License
private void exportPem(Object cert, File exportFile) throws IOException { Writer sw = null;/*from w ww. j av a 2 s . c om*/ JcaPEMWriter pw = null; try { sw = new FileWriter(exportFile); pw = new JcaPEMWriter(sw); pw.writeObject(cert); pw.flush(); } finally { IOUtils.closeQuietly(pw); IOUtils.closeQuietly(sw); } }
From source file:org.metaeffekt.dcc.commons.pki.CertificateManager.java
License:Apache License
private void persistPemObject(File file, Object serverCertificate) throws IOException { BufferedWriter out = new BufferedWriter(new FileWriter(file)); JcaPEMWriter writer = new JcaPEMWriter(out); try {//from ww w .j a va 2s.c o m writer.writeObject(serverCertificate); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(out); } }
From source file:org.metaeffekt.dcc.commons.pki.CertificateManager.java
License:Apache License
private void persistKey(File file, Key key) throws IOException { BufferedWriter out = new BufferedWriter(new FileWriter(file)); JcaPEMWriter writer = new JcaPEMWriter(out); try {/*from ww w .j ava2s . co m*/ writer.writeObject(key); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(out); } }
From source file:org.opcfoundation.ua.transport.security.BcCertificateProvider.java
License:Open Source License
/** * @param key/*from w w w.ja v a 2 s .co m*/ * certificate of private key * @param savePath * @param password * @param algorithm * @throws FileNotFoundException * @throws IOException */ public void writeToPem(X509Certificate key, File savePath, String password, String algorithm) throws IOException { JcaPEMWriter pemWrt = new JcaPEMWriter( new OutputStreamWriter(new FileOutputStream(savePath.getCanonicalPath()))); if (password == null) pemWrt.writeObject(key); else { PEMEncryptor encryptor = new JcePEMEncryptorBuilder(algorithm).setSecureRandom(CryptoUtil.getRandom()) .build(password.toCharArray()); pemWrt.writeObject(key, encryptor); } pemWrt.close(); }
From source file:org.opcfoundation.ua.utils.BouncyCastleUtils.java
License:Open Source License
/** * @param key certificate of private key * @param savePath//from ww w . java2 s . com * @param password * @param algorithm * @throws FileNotFoundException * @throws IOException */ public static void writeToPem(Object key, File savePath, String password, String algorithm) throws IOException { CryptoUtil.getSecurityProviderName(); JcaPEMWriter pemWrt = new JcaPEMWriter( new OutputStreamWriter(new FileOutputStream(savePath.getCanonicalPath()))); if (password == null) pemWrt.writeObject(key); else { char[] pw = password.toCharArray(); PEMEncryptor encryptor = new JcePEMEncryptorBuilder(algorithm).setSecureRandom(CryptoUtil.getRandom()) .build(pw); pemWrt.writeObject(key, encryptor); } pemWrt.close(); }
From source file:org.shredzone.acme4j.util.CertificateUtils.java
License:Apache License
/** * Writes an X.509 certificate PEM file. * * @param cert// ww w . j a v a 2s . co m * {@link X509Certificate} to write * @param w * {@link Writer} to write the PEM file to */ public static void writeX509Certificate(X509Certificate cert, Writer w) throws IOException { try (JcaPEMWriter jw = new JcaPEMWriter(w)) { jw.writeObject(cert); } }
From source file:org.shredzone.acme4j.util.CertificateUtils.java
License:Apache License
/** * Writes an X.509 certificate chain PEM file. * * @param chain/*from ww w .j av a 2 s . c om*/ * {@link X509Certificate[]} to write * @param w * {@link Writer} to write the PEM file to */ public static void writeX509CertificateChain(X509Certificate[] chain, Writer w) throws IOException { try (JcaPEMWriter jw = new JcaPEMWriter(w)) { for (X509Certificate cert : chain) { jw.writeObject(cert); } } }
From source file:org.shredzone.acme4j.util.KeyPairUtils.java
License:Apache License
/** * Writes a {@link KeyPair} PEM file./*from w ww. j a v a 2 s. co m*/ * * @param keypair * {@link KeyPair} to write * @param w * {@link Writer} to write the PEM file to */ public static void writeKeyPair(KeyPair keypair, Writer w) throws IOException { try (JcaPEMWriter jw = new JcaPEMWriter(w)) { jw.writeObject(keypair); } }