Showing posts with label SSL. Show all posts
Showing posts with label SSL. Show all posts

26/08/2018

[Java] Useful keytool commands

Keytool is a tool to manage Java keystores. Here are some useful commands to:

  • generate a new key and place it in a keystore:
keytool -genkey -keystore myKeystore.jks -storepass myPass -alias myKey -keyalg RSA -sigalg SHA256withRSA -keysize 2048 -validity 3650 -ext ku=digitalSignature

  • verify the content of a keystore:
keytool -list -keystore myKeystore.jks -storepass myPass -v

  • export the public key:
keytool -exportcert -keystore myKeystore.jks -storepass myPass -alias myAlias -rfc -file myPubKey.cer

  • delete a key:
keytool -delete -alias myAlias -keystore myKeystore.jks -storepass myPass

  • add a private key:
keytool -importkeystore -srckeystore myKeystore.jks -srcstorepass myPass -srcalias myAlias -destkeystore myNewKeystore.jks -deststorepass myNewPass -deststoretype JKS -destalias myNewAlias




  • add a public key:
keytool -import -noprompt -alias myAlias -keystore myKeystore.jks -file myPubKey.cer -storepass myPass

18/10/2014

[SSL] Create Java keystore from certificate and key

To create a Java keystore file from a certificate and key pair files, you can use the openssl and keytool commands.

First, convert the certificate to PKCS12 format:

openssl pkcs12 -export -in mycertificate.crt -inkey mykey.key -out mycertificate.p12

then create the keystore:

keytool -importkeystore -srckeystore mycertificate.p12 -srcstoretype PKCS12 -destkeystore mycertificate.jks -deststoretype JKS