Key Store Cheatsheet

Generate Keystore

keytool -genkey -alias certificatekey -keyalg RSA -validity 7 -keystore keystore.jks

List Contents of Java Key Store

keytool -list -keystore keystore.jks

Export the Public Key

keytool -export -alias certificatekey -keystore keystore.jks -rfc -file public.cert
keytool -export -alias 1 -v -keystore .keystore -rfc -file public.key

Export the Private Key ( using keytool )

keytool -v -importkeystore -srckeystore .keystore -srcalias 1 -destkeystore myp12file.p12 -deststoretype PKCS12

Export the Private Key ( using openssl )

openssl pkcs12 -in myp12file.p12 -out private.pem
openssl pkcs8 -topk8 -inform PEM -outform DER -in private.pem -out private.der -nocrypt