当我尝试将证书添加到密钥库时,我遇到一个奇怪的错误。
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));
谢谢。
在setCertificateEntry()中使用别名。使用keytool尝试。