导入新的 SSL 证书时出现 Keytool 错误“证书回复不包含公钥”或“回复中的公钥与密钥库不匹配”
Summary: 如果密钥库(根和从属 CA)中缺少受信任的全链证书或证书未从最后一个 CSR 签名,则在导入新的 SSL 证书时,Keytool 将引发错误“证书回复不包含公钥”或“回复中的公钥与密钥库不匹配”。
This article applies to
This article does not apply to
This article is not tied to any specific product.
Not all product versions are identified in this article.
Symptoms
# keytool -importcert -alias my-alias -keystore my-keystore.jks -trustcacerts -file my-signed-cert.pem
使用 keytool 导入证书会生成以下错误之一:
keytool error: java.lang.Exception: Certificate reply does not contain public key for my-alias
keytool error: java.lang.Exception: Public keys in reply and keystore don't matchCause
这些错误可能有多种原因,但它们主要与以下方面有关:
- 使用错误的密钥库文件
- 对于外部签名证书,缺少全链受信任证书(根和任何从属 CA)
- 尚未从上次生成的签名请求 (CSR) 签署证书
Resolution
通过检查模数(值必须相同),确保签名证书和 CSR 来自正确的密钥库(私钥):
# openssl pkcs12 -in my-keystore.jks -nodes -nocerts | openssl rsa -modulus -noout | openssl sha256
...
(stdin)= c46656d2c830cddba552198aa186ba4b13b0623d10d08768442fef28b9a4be4d
# openssl req -noout -modulus -in certreq.txt | openssl sha256
(stdin)= c46656d2c830cddba552198aa186ba4b13b0623d10d08768442fef28b9a4be4d
# openssl x509 -noout -modulus -in signed-cert.pem | openssl sha256
(stdin)= c46656d2c830cddba552198aa186ba4b13b0623d10d08768442fef28b9a4be4d
确保密钥库中存在根 CA 和从属证书:
# keytool -list -keystore my-keystore.jks
Your keystore contains 3 entries
my-alias, Sep 28, 2022, PrivateKeyEntry, ...
rootCA, Sep 28, 2022, trustedCertEntry, ...
intermediateCA, Sep 28, 2022, trustedCertEntry, ...
要导入外部签名的证书,主要步骤为:
1/ 在单独的密钥库文件中生成私钥:
# keytool -genkey -alias my-alias -keyalg RSA -keystore my-keystore.jks -storetype pkcs12
2/ 生成签名请求:
# keytool -certreq -keyalg RSA -alias my-alias -file my-sign-request.csr -keystore my-keystore.jks
3/ 获取由外部 CA 签署的 CSR。
您还需要信任所有证书:根和从属 CA。必须在单独的文件中(使用 PEM 格式)。
4/ 导入受信任的根 CA 证书:
# keytool -import -alias rootCA -keystore my-keystore.jks -trustcacerts -file root-CA.pem
5/ 导入中间证书:
# keytool -import -alias intermediateCA -keystore my-keystore.jks -trustcacerts -file intermediate-CA.pem
(使用唯一别名对签名链中的所有从属 CA 重复此作)
6/ 导入签名证书(使用与 CSR 中相同的别名):
6/ 导入签名证书(使用与 CSR 中相同的别名):
# keytool -import -alias my-alias -keystore my-keystore.jks -trustcacerts -file my-signed-cert.pem
本知识库文章重点介绍如何使用 Java keytool 实用程序通过外部签名的 SSL 证书正确构建密钥库。
有关 PowerFlex 实施详细信息,请参阅文档:
- 安全配置指南:PowerFlex Gateway
的证书管理- 自定义和配置 PowerFlex:安全性
Affected Products
PowerFlex rack, PowerFlex Appliance, PowerFlex custom node, ScaleIO, PowerFlex SoftwareArticle Properties
Article Number: 000206194
Article Type: Solution
Last Modified: 11 Apr 2025
Version: 3
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.