List of usage examples for org.bouncycastle.openssl.jcajce JcaPEMWriter writeObject
public void writeObject(PemObjectGenerator obj) throws IOException
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 www . j av a2s . 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 a v a 2 s. 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//www .jav a 2s . 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//ww w .j a v a 2s .co m * @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.xdi.oxauth.model.crypto.Certificate.java
License:MIT License
@Override public String toString() { try {/*from ww w . jav a2 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; } }