如何使用 java 密钥存储工具自动生成密钥存储

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

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

谢谢

44449 次浏览

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

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

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