java.security.cert.CertificateParsingException:签名字段无效



我正在尝试阅读X509 certificate

FileInputStream fr = new FileInputStream("suresh.pfx");
CertificateFactory cf =   CertificateFactory.getInstance("X509");
X509Certificate c = (X509Certificate) cf.generateCertificate(fr); 

并遇到异常

java.security.cert.CertificateParsingException: signed fields invalid
    at sun.security.x509.X509CertImpl.parse(Unknown Source)
    at sun.security.x509.X509CertImpl.<init>(Unknown Source)
    at sun.security.provider.X509Factory.engineGenerateCertificate(Unknown Source)
    at java.security.cert.CertificateFactory.generateCertificate(Unknown Source)
    at com.nextenders.certificategeenrator.CertificateGenerator.testGenerateSignCertWithKeyStore(CertificateGenerator.java:102)
    at com.nextenders.certificategeenrator.CertificateGenerator.main(CertificateGenerator.java:65)

从甲骨文论坛中找到与之相关的内容,但没有解决方案。

有什么提示吗?

PFX 本身不是证书,而是一个密钥库。

要获取证书,您必须将 pfx 加载到密钥库中,然后获取证书:

InputStream certIs=new FileInputStream("suresh.pfx");
Keystore ks=KeyStore.getInstance("PKCS12");
ks.load(certIs.getInputStream(),"password".toCharArray());
Certificate cert=ks.getCertificate("alias");

问候

相关内容

  • 没有找到相关文章

最新更新