Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问"

2022-01-25 00:00:00 ssl ssl-certificate java keytool

我正在尝试通过 HTTPS 连接 Java Web API;但是,抛出异常:

I'm trying to connect a Java Web API via HTTPS; however, an exception is thrown:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException

我按照我从在线 keytool & 中学到的这些步骤进行操作.SSL 证书教程:

I followed these steps which I learned from online keytool & SSL cert tutorials:

  1. 我将 HTTPS URL 复制到浏览器中,下载了 SSL 证书 &使用 Internet Explorer 在浏览器中安装它们.

  1. I copied the HTTPS URL into the browser, downloaded the SSL certificates & Installed them in the browser using Internet Explorer.

将证书导出到我电脑上的某个路径,证书保存为.cer

Exported the certificates to a path on my computer, the certificates were saved as .cer

使用了 keytool 的导入选项.下面的命令执行没有任何错误.

Used the keytool's import option. The command below executed without any errors.

keytool -import -alias downloadedCertAlias -keystore C:path	omykeystorecacerts.file -file C:pathofexportedCert.cer

  • 在命令提示符处提示我输入密码,然后我输入了密码,然后我通过了身份验证.

  • I was prompted for a password at the command prompt, which I entered then I was authenticated.

    cmd窗口打印了一些证书数据&签名,我被提示了一个问题:

    The cmd window printed some certificate data & signatures and I was prompted with the question:

    信任此证书?

    我回答是.

    显示的cmd提示符

    证书已添加到密钥库

    但是在那条消息之后,显示了另一个异常:

    However after that message, another exception was displayed:

    keytool error: java.io.FileNotFoundException: C:Program files...cacerts <Access Denied>
    

  • 最后,当我检查 keystore 时,没有添加 SSL 证书,我的应用程序给出了与我之前尝试连接时相同的异常:

    Finally when I checked the keystore , the SSL certificate was not added and my application gives the same exception I was getting earlier when trying to connect:

    (javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException)
    

    推荐答案

    如果您没有在管理员模式下运行命令提示符,可能会发生这种情况.如果您使用的是 Windows 7,则可以运行,输入 cmd 并按 Ctrl+Shift+enter.这将以管理员模式打开命令提示符.如果没有,您也可以转到开始 -> 所有程序 -> 附件 -> 右键单击​​命令提示符,然后单击以管理员身份运行".

    This could happen if you are not running the command prompt in administrator mode. If you are using windows 7, you can go to run, type cmd and hit Ctrl+Shift+enter. This will open the command prompt in administrator mode. If not, you can also go to start -> all programs -> accessories -> right click command prompt and click 'run as administrator'.

    相关文章