How to automate Keystore generation using the java

2019-01-21 07:15发布

I am trying to automate keystore generation using the Java keystore tool. The command I am using is :

keytool -keystore keystore -alias jetty -genkey -keyalg RSA

But after this command, user is required to enter certain inputs as follows:

Enter keystore password:  password
What is your first and last name?  
[Unknown]:  jetty.mortbay.org  
What is the name of your organizational unit?  
[Unknown]:  Jetty  
What is the name of your organization?  
[Unknown]:  Mort Bay Consulting Pty. Ltd.  
What is the name of your City or Locality?  
[Unknown]:  
What is the name of your State or Province?  
[Unknown]:  
What is the two-letter country code for this unit?  
[Unknown]:  
Is CN=jetty.mortbay.org, OU=Jetty, O=Mort Bay Consulting Pty. Ltd.,  
L=Unknown, ST=Unknown, C=Unknown correct?  
[no]:  yes  

Enter key password for <jetty>  
(RETURN if same as keystore password):  password  

Instead of the user entering these values , is there any way of providing these values without user interaction ,either within the command or through a script?

Thanks

标签: java keystore
3条回答
Root(大扎)
2楼-- · 2019-01-21 07:45

Try this:

keytool -genkey -noprompt \
 -alias alias1 \
 -dname "CN=mqttserver.ibm.com, OU=ID, O=IBM, L=Hursley, S=Hants, C=GB" \
 -keystore keystore \
 -storepass password \
 -keypass password
查看更多
霸刀☆藐视天下
3楼-- · 2019-01-21 07:55

See the full documentation about command line or by typing keytool without any arguments.

Specifically you may want to look options -storepass password -keypass password

查看更多
再贱就再见
4楼-- · 2019-01-21 07:59

don't forget -noprompt, otherwise you will be asked to input Yes or No

查看更多
登录 后发表回答