gpt4 book ai didi

java - 将公共(public)证书导入 keystore 时出错

转载 作者:行者123 更新时间:2023-12-01 16:15:04 26 4
gpt4 key购买 nike

我有来自 CA 的公共(public)证书。我想使用此证书创建 Java SSL 连接。我提到How can I use different certificates on specific connections?Java SSL connection with self-signed certificate without copying complete keystore to client 。由此我了解到我需要将证书导入 keystore 。但是我还没有收到来自 CA 的任何 keystore 。我创建了一个 keystore 并尝试将公共(public)证书导入其中。但后来我收到以下错误:

keytool 错误:java.lang.Exception:回复中的公钥与 keystore 不匹配

我需要来自 CA 的 keystore 还是我做错了什么?

<小时/>

用于创建 keystore 的命令:

keytool -genkey -alias tomcat -keyalg RSA -keystore keystore.jks

用于导入证书的命令:

keytool -import -v -alias tomcat -file signed-cert.pem -keystore keystore.jks

最佳答案

我认为您没有正确遵循证书登录流程。查看此讨论 https://forums.oracle.com/thread/1533940按照以下步骤正确实现它们:

  1. 创建 keystore keytool -genkey -keyalg RSA -keystore test.keystore -validity 360(这会生成一个 keystore 和一个别名为“mykey”的 key (DC))

  2. 创建证书签名请求 (CSR)。 keytool -certreq -keyalg RSA -file test.csr -keystore test.keystore(这会生成一个文本 CSR 文件)

  3. 已生成签名证书:http://www.instantssl.com/ssl-certificate-support/csr_generation/ssl-certificate-index.html

  4. 导入的签名证书(如果粘贴步骤 3 中的签名证书,请注意 CRLF) keytool -import -alias newkey -file <signed cert file> -keystore test.keystore(?重要的是,这有一个与步骤 1 不同的别名(默认为“mykey”)?

  5. 导出公钥以供客户端使用 keytool -export -alias mykey -file test.publickey -keystore test.keystore

在服务器系统上

  • 创建信任库 keytool -genkey -keyalg RSA -keystore test.truststore -validity 360(这会生成一个 keystore 和一个别名为“mykey”的 key (DC))

  • 导入公钥 - 用于通过客户端测试 SSL SOAP 服务 keytool -import -file test.publickey -keystore test.truststore

  • 问题在于让步骤 1 和 6 中的别名默认为“mykey”。当我将步骤 6 更改为: keytool -genkey -alias testAlias -keyalg RSA -keystore test.truststore -validity 360

    您可以使用上面的步骤 7 进行导入(尽管我在步骤 7 中添加了“-alias apublickey ”)。这对我有用。

    关于java - 将公共(public)证书导入 keystore 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62422030/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com