PEM to P12 and P12 to PEM and PEM to JKS and P12 to JKS

PEM to P12

openssl pkcs12 -export -in usercert.pem -inkey userkey.pem -out mycert.p12

P12 to PEM

openssl pkcs12 -nocerts -in mycert.p12 -out userkey.pem
openssl pkcs12 -clcerts -nokeys -in mycert.p12 -out usercert.pem
chmod 0400 userkey.pem
chmod 0600 usercert.pem

PEM to JKS

keytool -import -file userkey.pem -keystore keystore.jks \
-storepass _store_password_comes_here_

P12 to JKS

keytool -v -importkeystore -srckeystore mycert.p12 \
-srcstoretype PKCS12 -destkeystore truststore.jks -deststoretype JKS

Read certificate using openssl

openssl x509 -in cert.pem -text -noout

Verify whether private key and cert match

openssl x509 -noout -modulus -in cert.pem | openssl md5
openssl rsa -noout -modulus -in privkey.pem | openssl md5