【问题标题】:Java Keystore unable to add X509Certificate to KeystoreJava Keystore 无法将 X509Certificate 添加到 Keystore
【发布时间】:2020-02-12 18:38:07
【问题描述】:

当我尝试将证书添加到 Keystore 时,我遇到了一个奇怪的错误。

System.out.println(x509Certificate.getPublicKey()); // prints public key, certificate is valid
GlobalStoreManager.getInstance().getSPATruststore().setCertificateEntry(name, x509Certificate); // no error
System.out.println(GlobalStoreManager.getInstance().getSPATruststore().getCertificate(name)); // null

为什么setCertificateEntry 没有抛出任何错误,而getCertificate 仍然返回null?

更新:

我尝试在调用setCertificateEntry() 后立即获取证书别名并且它有效??!所以问题似乎出在getCertificate() 调用而不是setCertificateEntry() 调用?

System.out.println(GlobalStoreManager.getInstance().getSPATruststore().getCertificateAlias(x509Certificate));

谢谢。

【问题讨论】:

  • 你的密钥位大小是多少?
  • @Rookie007 2048
  • @Rookie007 也请查看我的更新
  • 在你的机器上安装了证书
  • @SapneshNaik 好吧,这可能不是原因,最好检查一下你的 java 的位大小是否超过256。因为当您尝试设置证书时它甚至没有设置,所以它总是null

标签: java spring-boot x509certificate keystore


【解决方案1】:

在 setCertificateEntry() 中使用别名。用 keytool 试试吧。

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 2011-02-26
    • 2012-08-25
    相关资源
    最近更新 更多