如何使用java密钥库工具自动生成密钥库?没有用户互动

时间:2012-11-27 05:51:46

标签: java keystore

我正在尝试使用Java密钥库工具自动生成密钥库。我正在使用的命令是:

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

但是在此命令之后,用户需要按如下方式输入某些输入:

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  

有没有用户输入这些值,有没有办法在命令内或通过脚本提供这些值而无需用户交互?

由于

3 个答案:

答案 0 :(得分:132)

试试这个:

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

答案 1 :(得分:6)

不要忘记-noprompt,否则你会被要求输入是或否

答案 2 :(得分:4)

请参阅full documentation about command line 或输入keytool,不带任何参数。

具体而言,您可能希望查看选项-storepass password -keypass password