如何使用Java密钥工具来自动密钥库代? W / O型的用户交互(How to automate

2019-07-04 03:32发布

我试图使用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  

代替输入这些值的用户,是否有没有用户交互提供这些值的任何方式,无论是在命令内或通过一个脚本?

谢谢

Answer 1:

试试这个:

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


Answer 2:

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



Answer 3:

请参阅有关命令行完整的文档或者输入keytool不带任何参数。

具体来说,你可能想看看选项-storepass password -keypass password



文章来源: How to automate Keystore generation using the java keystore tool? w/o user interaction
标签: java keystore