Java programmatically create truststore and import certificates into it

Veröffentlicht am: 19 Januar 2022
auf dem Kanal: Rahul Random Learnings
23,990
229

In this video we are going to setup truststore and then load certificates in it programmatically.
Up till now we were manually generating truststore and then loading certs in it, doing it using code means that, instead of opening a command prompt or git bash or a terminal window then using keytool to generate a truststore and then importing all certificates one by one, we will simply use code to generate a truststore and then load all certs using a loop.
truststore will be generated in-memory we will then we will write it to disk.
Once it is saved to a location, we will then set that location in java system properties and then use the saved truststore to connect to the URL that is giving us the PKIX or SSL Handshake exception.

Now I will be creating the truststore and then storing it in temp directory, as once the connection is complete, I will then use java File class to delete the file on exit.
This approach is helpful if you want to simply add certs to a location and want all certs to be auto loaded when program runs, this way when a cert expires you can simply update the cert and trigger a redeploy.

We will use java system property to get the temp folder, java separator to automatically apply the correct path separator like forward or backslash depending on the OS the program is running and auto closable logic to automatically close the file writers once the truststore is written.

please see github code for same: https://github.com/chandnarahul/java_...


Channel #Rahul Random Learnings #RahulRandomLearnings #RahulRandom Learnings Opinion Disclaimer:
The views and opinions expressed here are my own and not the views of my employer.
The content uploaded on my channel is not intended to malign any religion, ethic group, club, organization, company, individual or anyone or anything.


Auf dieser Seite können Sie das Online-Video Java programmatically create truststore and import certificates into it mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Rahul Random Learnings 19 Januar 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 23,990 Mal angesehen und es wurde von 229 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!