Importing Keystore example using keytool in Java
By: Manoj Kumar
The command "importkeystore" is used to import an entire keystore into another keystore, which means all entries from the source keystore, including keys and certificates, are all imported to the destination keystore within a single command. You can use this command to import entries from a different type of keystore. During the import, all new entries in the destination keystore will have the same alias names and protection passwords (for secret keys and private keys). If keytool has difficulties recover the private keys or secret keys from the source keystore, it will prompt you for a password. If it detects alias duplication, it will ask you for a new one, you can specify a new alias or simply allow keytool to overwrite the existing one.
For example, to import entries from a normal JKS type keystore key.jks into a PKCS #11 type hardware based keystore, you can use the command:
keytool -importkeystore
-srckeystore key.jks -destkeystore NONE
-srcstoretype JKS -deststoretype PKCS11
-srcstorepass changeit -deststorepass topsecret
The importkeystore command can also be used to import a single entry from a source keystore to a destination keystore. In this case, besides the options you see in the above example, you need to specify the alias you want to import. With the srcalias option given, you can also specify the desination alias name in the command line, as well as protection password for a secret/private key and the destination protection password you want. In this way, you can issue a keytool command that will never ask you a question. This makes it very convenient to include a keytool command into a script file, like this:
keytool -importkeystore
-srckeystore key.jks -destkeystore NONE
-srcstoretype JKS -deststoretype PKCS11
-srcstorepass changeit -deststorepass topsecret
-srcalias myprivatekey -destalias myoldprivatekey
-srckeypass oldkeypass -destkeypass mynewkeypass
-noprompt
Archived Comments
1. Please let me know if you're looking for a article author
for your site. You have some reall
View Tutorial By: Dessie at 2017-08-13 14:07:21
2. I don't even know how I ended up here, but I thought this post was great.
I don't kno
View Tutorial By: Captcha solving Services at 2017-08-03 04:39:04
3. Thanks Manoj. This was very helpful.
View Tutorial By: Niraj at 2011-10-05 10:59:36
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java