Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To set an alias while using keytool to import a keystore in Java, use the -alias command-line option when importing the certificate.

Syntax:

keytool -importkeystore -srckeystore [source-keystore] -destkeystore [destination-keystore] -srcalias [source-alias] -destalias [destination-alias]

where

  • [source-keystore] is the path to the keystore containing the certificate to be imported
  • [destination-keystore] is the path to the keystore into which the certificate will be imported
  • [source-alias] is the alias of the certificate in the source keystore
  • [destination-alias] is the new alias for the imported certificate in the destination keystore

Example:

keytool -importkeystore -srckeystore mykeystore.p12 -srcstoretype PKCS12 -destkeystore mykeystore.jks -deststoretype JKS -srcalias mycert -destalias mynewalias

This command imports the certificate with alias "mycert" from the PKCS12 keystore "mykeystore.p12" and saves it with a new alias "mynewalias" in the JKS keystore "mykeystore.jks".