Recently, someone asked me to add key like this
-----BEGIN CERTIFICATE-----
MIIDT.....
.....
.....w8XMWhBI=
-----END CERTIFICATE-----
to my keystore.
Before, I was usually adding a file like a .pem file to keystore so adding just bunch of text like this to keystore was bit confusing to me and I could not find much info online, so I decided to create SO and provide solution.
Now you can use java keytool to add the .pem certificate to your java keystore:
keytool -import -alias my.cert.file.tls -keystore ./cacerts -file C:\me\my.cert.file.tls.pem
To confirm the pem certificate is imported, use
keytool -list -keystore cacerts
I did all this in OpenJdk11.