예제 #1
0
 public void writeToFile(File certFile, File keyFile)
     throws IOException, CertificateEncodingException {
   FileOutputStream keyOutputStream = null;
   FileOutputStream certOutputStream = null;
   try {
     keyOutputStream = new FileOutputStream(keyFile);
     certOutputStream = new FileOutputStream(certFile);
     saveKey(keyOutputStream);
     saveCertificateChain(certOutputStream);
   } finally {
     try {
       if (keyOutputStream != null) {
         keyOutputStream.close();
       }
     } catch (IOException e) {
       logger.warn("Could not close stream on save of key to file. " + keyFile.getPath());
     }
     try {
       if (certOutputStream != null) {
         certOutputStream.close();
       }
     } catch (IOException e) {
       logger.warn(
           "Could not close stream on save certificate chain to file. " + certFile.getPath());
     }
   }
 }
예제 #2
0
 public void save(OutputStream out) throws IOException, CertificateEncodingException {
   CertificateIOUtil.writeCertificate(out, this.certChain[0]);
   saveKey(out);
   for (int i = 1; i < this.certChain.length; i++) {
     // This will skip the self-signed certificates?
     if (this.certChain[i].getSubjectDN().equals(certChain[i].getIssuerDN())) {
       continue;
     }
     CertificateIOUtil.writeCertificate(out, this.certChain[i]);
   }
   out.flush();
 }