private String saveCertificateAsPEMFile ( Object x509Certificate , String filename , boolean deleteOnExit ) throws IOException { File pemFile = File . createTempFile ( filename , null ) ; try ( FileWriter pemfileWriter = new FileWriter ( pemFile ) ) { try ( JcaPEMWriter jcaPEMWriter = new JcaPEMWriter ( pemfileWriter ) ) { jcaPEMWriter . writeObject ( x509Certificate ) ; } } if ( deleteOnExit ) { pemFile . deleteOnExit ( ) ; } return pemFile . getAbsolutePath ( ) ; }
Saves X509Certificate as Base - 64 encoded PEM file .