Exporting certificates from a Java keystore

There is a patently easy way to convert JKS keystores to PKCS12 certificate bundles (and vice versa). It’s a (poorly documented) keytool command that was introduced with JDK 6:

Convert JKS to P12

keytool -importkeystore -srckeystore keystore.jks -srcstoretype JKS -deststoretype PKCS12 -destkeystore keystore.p12

Convert P12 to JKS

keytool -importkeystore -srckeystore keystore.p12 -srcstoretype PKCS12 -deststoretype JKS -destkeystore keystore.jks

Borrowed from a blog post by tomas at EJBCA.