Convert JKS and PKCS12 back and forth with keytool

Introduction

Here are a few CLI commands to convert a java key store file to a PKCS12 encoded cert chain and back. This requires the java development kit (Sun/Oracle JDK) 6 or newer.  

Instructions

JKS → P12

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

P12 → JKS

$> keytool -importkeystore \
-srckeystore keystore.p12 \
-srcstoretype PKCS12 \
-deststoretype JKS \
-destkeystore keystore.jks
References

http://blog.ejbca.org/2008/02/converting-keystores-between-jks-and.html