Java密钥库无法将X509证书添加到密钥库

问题描述 投票:1回答:1

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

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));

谢谢。

java spring-boot x509certificate keystore
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.