Java 添加自签名证书而不提示用户是/否

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24532103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:46:31  来源:igfitidea点击:

Add Self Signed Certificate without promting Yes/No from User

javasslimportkeystorekeytool

提问by Arun Kumar

Using some batch file, I want to add the untrusted self signed certificate within Java Keystore.

使用一些批处理文件,我想在 Java Keystore 中添加不受信任的自签名证书。

Command is

命令是

%JAVA_HOME%/bin/keytool -import -v -trustcacerts -alias server-alias
-file server.cer -keystore cacerts.jks -keypass changeit -storepass changeit

After running above command, the screen promts for Trust of certificate using Y/N.

运行上述命令后,屏幕提示使用 Y/N 的证书信任。

Trust this certificate? [no]:

But I don't want to provide Y/N here.

但我不想在这里提供 Y/N。

Is there a way to complete the import using a single command or some additional import switch if any?

有没有办法使用单个命令或一些额外的导入开关来完成导入(如果有)?

采纳答案by Arun Kumar

The option -nopromptdoesn't prompt the input Y/N from a user and assumes yes.

该选项-noprompt不会提示用户输入 Y/N 并假定yes.

More details can found by running command keytool -importcert -helpon terminal.

通过keytool -importcert -help在终端上运行命令可以找到更多详细信息。

回答by Carlos

As such, keytool is most likely looking for "yes" in your locale ("si" in this case).

因此,keytool 很可能在您的语言环境中寻找“是”(在本例中为“si”)。