Skip to content

Instantly share code, notes, and snippets.

@binhqd
Forked from votienan123/1_Create new keystore.sh
Last active July 9, 2018 03:24
Show Gist options
  • Save binhqd/562ffd64f8259f49a241c9eecc8cb04d to your computer and use it in GitHub Desktop.
Save binhqd/562ffd64f8259f49a241c9eecc8cb04d to your computer and use it in GitHub Desktop.
keytool -genkey -alias quangnam -keyalg RSA -keysize 2048 -keystore quangnam.jks -dname "CN=localhost,OU=Home,O=Home,L=SL,S=WS,C=LK" -storepass quangnam -keypass quangnam
openssl x509 -out mycert.crt.pem -outform pem -in mycert.crt -inform der
keytool -exportcert -keystore quangnam.jks -file mycert.crt -alias quangnam
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile more.crt
keytool -export -alias quangnam -keystore quangnam.jks -file quangnam.pem

Here is what I do,

First export the key :

keytool -importkeystore -srckeystore mycert.jks -destkeystore keystore.p12 -deststoretype PKCS12

For apache ssl certificate file you need certificate only:

openssl pkcs12 -in keystore.p12 -nokeys -out my_key_store.crt

For ssl key file you need only keys:

openssl pkcs12 -in keystore.p12 -nocerts -nodes -out my_store.key

$JAVA_HOME/bin/keytool -importkeystore -srckeystore quangnam.jks -destkeystore quangnam.p12 -deststoretype PKCS12
keytool -importkeystore -deststorepass an123456 -destkeypass an123456 -destkeystore quangnam-keystore.jks -srckeystore quangnam.jks -srcstorepass quangnam -alias app4
keytool -import -alias quangnam -file quangnam.pem -keystore quangnam-truststore.jks -storepass quangnam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment