67

How can I convert a .jks file to p12. jks is a java key store file so how can I convert it to the p12 format?

Celada
  • 21,627
  • 4
  • 64
  • 78
Matrix
  • 7,477
  • 14
  • 66
  • 97
  • 18
    You should accept some answers to your previous questions. – Emil May 17 '10 at 07:12
  • @Matrix do you really find none of the answers below acceptable? With your rep and badges, you should accept or comment as to why none of these are acceptable. – JoeG Feb 14 '17 at 17:52

5 Answers5

106

Convert a JKS file to PKCS12 format (Java 1.6.x and above)

keytool \
    -importkeystore              \
    -srckeystore    KEYSTORE.jks \
    -destkeystore   KEYSTORE.p12 \
    -srcstoretype   JKS          \
    -deststoretype  PKCS12       \
    -srcstorepass   mysecret     \
    -deststorepass  mysecret     \
    -srcalias       myalias      \
    -destalias      myalias      \
    -srckeypass     mykeypass    \
    -destkeypass    mykeypass    \
    -noprompt

from A few frequently used SSL commands

StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
Daniel Silveira
  • 41,125
  • 36
  • 100
  • 121
  • That's a useful link. Thanks. – dajames Nov 20 '10 at 14:06
  • Does this conversion only needs to be done for Java 1.6.x and above? I ask because I am on Java 1.7.x and faced a problem where WSKeystore class could not read the cacerts (default keystore file) until I converted it to cacerts.p12. – Prince Dec 11 '13 at 20:12
  • 4
    Note that supplying the passwords directly in the command is not a secure practice in general (as noted in the keytool manpage) as the passwords could then be read from your command history or observed with `ps`. If you omit a password, the tool should prompt you for it. – Aaron Novstrup May 06 '14 at 19:37
  • You've saved my day [Daniel Silveira](/users/1100/daniel-silveira). Thanks for the help. – Anurag Mar 25 '15 at 11:19
  • "Warning: Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified -destkeypass value.", https://bugs.openjdk.java.net/browse/JDK-8008292 - so if you want that, you need to use something else – eis Aug 12 '17 at 09:25
56

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
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
bob
  • 1,107
  • 10
  • 16
4

Here is a one line command for the same.

keytool -importkeystore -srckeystore <MY_KEYSTORE.jks> -destkeystore <MY_FILE.p12> -srcstoretype JKS -deststoretype PKCS12 -deststorepass <PASSWORD_PKCS12> -srcalias <ALIAS_SRC> -destalias <ALIAS_DEST>

Explaining the parameters :

MY_FILE.p12: path to the PKCS#12 file (.p12 or .pfx extension) that is going to be created.
MY_KEYSTORE.jks: path to the keystore that you want to convert.
PASSWORD_PKCS12: password that will be requested at the PKCS#12 file opening.
ALIAS_SRC: name matching your certificate entry in the JKS keystore, "tomcat" for example.
ALIAS_DEST: name that will match your certificate entry in the PKCS#12 file, "tomcat" for example.
Ashish K
  • 905
  • 10
  • 27
2

This is for future folks, I found the above answers outdated and on mac I used this command to convert JKS to PKCS12

keytool -importkeystore -srckeystore srckeystore.jks -destkeystore destkeystore.jks -deststoretype pkcs12
Kanishk Gupta
  • 369
  • 2
  • 10
1

You can use, https://keystore-explorer.org/ Open your jks and save as p12 or open p12 and save as jks.

noobius
  • 1,529
  • 7
  • 14