100

我正在尝试使用 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  

除了用户输入这些值之外,有没有什么方法可以在没有用户交互的情况下提供这些值,无论是在命令中还是通过脚本?

谢谢

4

3 回答 3

178

试试这个:

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
于 2012-11-27T06:22:32.817 回答
15

不要忘记 -noprompt,否则会要求你输入 Yes 或 No

于 2016-08-30T00:54:53.860 回答
5

查看有关命令行的完整文档keytool或不带任何参数 键入。

具体来说,您可能想要查看选项-storepass password -keypass password

于 2012-11-27T06:10:41.253 回答