public static String toPEM(Collection<X509Certificate> x509Certificates) { X509Certificate[] certs = new X509Certificate[x509Certificates.size()]; certs = x509Certificates.toArray(certs); return toPEM(certs); }
/** * Encode the certificates with the the default (PKCS 12). * @param x509Certificates * @param out */ public static void toPEM(Collection<X509Certificate> x509Certificates, OutputStream out) { X509Certificate[] certs = new X509Certificate[x509Certificates.size()]; certs = x509Certificates.toArray(certs); toPEM(certs, out); }
public static void toPEM(X509Certificate[] x509Certificates, OutputStream out) { PrintStream printStream = new PrintStream(out); printStream.print(toPEM(x509Certificates)); printStream.flush(); }
public static String toPEM(X509Certificate[] x509Certificates) { StringBuffer stringBuffer = new StringBuffer(); boolean firstPass = true; for (X509Certificate x509Certificate : x509Certificates) { if (firstPass) { stringBuffer.append(toPEM(x509Certificate)); firstPass = false; } else { stringBuffer.append("\n" + toPEM(x509Certificate)); } } return stringBuffer.toString(); }
/** * Writes the retrieved credentials to the specified output stream. * * @param os OutputStream to write to * @throws IOException * @throws GeneralSecurityException */ public void saveCredentials(OutputStream os) throws IOException, GeneralSecurityException { CertUtil.toPEM(certificateChain, os); // since we are putting the private key in the same file as the certs, we have to // add a new line. os.write('\n'); KeyUtil.toPKCS1PEM(keypair.getPrivate(), os); }
/** * Encode to PEM. * * @param x509Certificate * @return */ public static String toPEM(X509Certificate x509Certificate) { try { // The issue is that getEncoded returns a byte array in DER format, but // the inverse operation from the cert factory expects the header and strips it off. ByteArrayOutputStream baos = new ByteArrayOutputStream(); toPEM(x509Certificate, baos); return new String(baos.toByteArray(), UTF_8); } catch (Exception e) { throw new GeneralException("Error encoding cert", e); } }
/** * If the state supports this, it will save the current cert to a file. The complete filename must be supplied, * including any path. * * @param inputLine * @throws Exception */ public void savecert(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { saveCertHelp(); return; } if (assetResponse == null) { say("Sorry, but there is no cert to save. Please do a successful getcert call first."); return; } String cert = CertUtil.toPEM(assetResponse.getX509Certificates()); if (!inputLine.hasArgs()) { say("Sorry. You did not specify a file so the cert cannot be saved."); return; } String fileName = inputLine.getArg(1); FileWriter fileWriter = new FileWriter(fileName); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(cert + "\n"); bufferedWriter.flush(); bufferedWriter.close(); say("File \"" + fileName + "\" saved successfully."); }
public void getcert(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { getCertHelp(); return; } assetResponse = getOA2S().getCert(dummyAsset, currentATResponse); if (assetResponse.getUsername() != null) { say("returned username=" + assetResponse.getUsername()); } say("X509Certs:"); say(CertUtil.toPEM(assetResponse.getX509Certificates())); }
request.setAttribute("cert", CertUtil.toPEM(assetResponse.getX509Certificates())); request.setAttribute("username", assetResponse.getUsername());
request.setAttribute("cert", CertUtil.toPEM(assetResponse.getX509Certificates())); request.setAttribute("username", assetResponse.getUsername());
@Override public void toMap(Asset asset, ConversionMap<String, Object> map) { super.toMap(asset, map); if (asset.getPrivateKey() != null) { map.put(getAR().privateKey(), KeyUtil.toPKCS8PEM(asset.getPrivateKey())); } if(asset.getRedirect() != null){ map.put(getAR().redirect(), asset.getRedirect().toString()); } if(asset.getCertificates()!= null){ map.put(getAR().certificates(), CertUtil.toPEM(asset.getCertificates())); } if(asset.getUsername() != null && 0 < asset.getUsername().length()){ map.put(getAR().username(), asset.getUsername()); } if(asset.getCreationTime() != null){ map.put(getAR().creationTime(), asset.getCreationTime()); } if(asset.getCertReq() != null){ map.put(getAR().certReq(), CertUtil.fromCertReqToString(asset.getCertReq())); } if(asset.getToken() != null){ map.put(getAR().token(), asset.getToken()); } }