Java 如何通过keytool命令删除已经导入的证书/别名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48204014/
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
How to delete already import certificate/alias by keytool command?
提问by Subodh Joshi
I am trying to delete already import certificate by keytool command
我正在尝试通过 keytool 命令删除已经导入的证书
keytool -delete -noprompt -alias "initcert" -keystore keycloak.jks
But getting below exception
但低于例外
keytool error: java.lang.Exception: Keystore file does not exist: keycloak.jks
密钥工具错误:java.lang.Exception:密钥库文件不存在:keycloak.jks
Same issue with
同样的问题
keytool -delete -alias "initcert" -keystore keycloak.cer
issue
问题
keytool error: java.lang.Exception: Keystore file does not exist: keycloak.cer
密钥工具错误:java.lang.Exception:密钥库文件不存在:keycloak.cer
Now i am trying to import the certificate with same alias name
现在我正在尝试导入具有相同别名的证书
keytool -import -noprompt -trustcacerts -alias "initcert" -file "C:\Code_Base\keycloak_certificates\keycloak_135.250.138.74_server\keycloak.cer" -keystore "C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts"
But again end with
但再次以
keytool error: java.lang.Exception: Certificate not imported, alias already exists
keytool 错误:java.lang.Exception:未导入证书,别名已存在
采纳答案by Praveen
You can make use of KeyStore Explorerto check if exists and manage your certs easily,
您可以使用KeyStore Explorer检查是否存在并轻松管理您的证书,
KeyStore Explorer Download Link
Just open your keystore filewith the explorer, do the stuff you want and save it back.
只需使用资源管理器打开您的密钥库文件,执行您想要的操作并将其保存回来。
回答by mardo
It seems you didn't write the full keystore path. The command should be like this:
您似乎没有编写完整的密钥库路径。命令应该是这样的:
keytool -delete -noprompt -alias "initcert" -keystore "C:\Path\to\your\keystore\keycloak.jks"
About the last error, as other pointed out, "cacerts" is different keystore than your keycloak where you have already imported your certificate. You can check if your alias is in there by using the following command:
关于最后一个错误,正如其他人指出的那样,“cacerts”与您已经导入证书的密钥库不同。您可以使用以下命令检查您的别名是否在那里:
keytool -list -keystore "C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts"
And to delete it:
并删除它:
keytool -delete -noprompt -trustcacerts -alias "initcert" -keystore "C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts"
Then, if you import again the certificate, the error would not appear.
然后,如果您再次导入证书,则不会出现该错误。
Finally, one last thing, if there is an error like this
最后,最后一件事,如果出现这样的错误
keytool error: java.io.FileNotFoundException: C:\Path\to\your\keystore\keycloak.jks (Permission denied)
密钥工具错误:java.io.FileNotFoundException:C:\Path\to\your\keystore\keycloak.jks(权限被拒绝)
You should execute the command window in Administrator mode.
您应该在管理员模式下执行命令窗口。