Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have a keystore.jks file with multiple certificate including public and private key
- This "all-public-cert.crt" file contain only certificate (public key only) . should not contain any private key in this file.
- String keystorePath = ....
- InputStream is = new FileInputStream(new File(keystorePath));
- KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
- keystore.load(is, "keystorePassword".toCharArray());
- Enumeration e = ks.aliases();
- Set<Certificate> certs = new HashSet<Certificate>();
- while (e.hasMoreElements()) {
- Certificate cert = ks.getCertificate((String) enumeration.nextElement());
- certs.add(cert);
- }
- String pathToStoreTheCerts = ...
- File path = new File(pathToStoreTheCerts);
- OutputStream os = null;
- for (X509Certificate cert : certs) {
- File certFile = new File(path, cert.getSubjectX500Principal().getName() + ".crt");
- os = new FileOutputStream(certFile);
- os.write(cert.getEncoded());
- os.flush();
- }
- os.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement