Search results
Create KeyStore / TrustStore with Certificates Programmatically
KeyStoreUtils.java
:
public static void createKeyStore(List<String> certFilesPaths, String keyStorePath, String keyStorePasswd)
throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(null, null);
for (String certFile : certFilesPaths) {
try (FileInputStream certificateStream = new FileInputStream(new File(certFile))) {
while (certificateStream.available() > 0) {
Certificate certificate = CertificateFactory.getInstance("X.509").generateCertificate(certificateStream);
keyStore.setCertificateEntry(certFile, certificate);
}
}
}
keyStore.store(new FileOutputStream(keyStorePath), keyStorePasswd.toCharArray());
}
Usage
KeyStoreUtils.createKeyStore(
Lists.newArrayList("<the path to>/cosmos-db-emulator.pem"),
trustStorePath,
"changeit"
);
with VM arguments:
javax.net.ssl.trustStore: <the path to>/keyStorePath
javax.net.ssl.trustStorePassword: changeit
javax.net.ssl.trustStoreType: PKCS12
Certificate content
Tip:
Saving the PEM certificate is a manual process.
Read on if you are interested in learning how to extract a certificate and add it to a Truststore programmatically.
Saving the PEM certificate is a manual process.
Read on if you are interested in learning how to extract a certificate and add it to a Truststore programmatically.
View Website’s Public Certificate
Save Website’s Public PEM Certificate