0

我想讀一個X509 certificatejava.security.cert.CertificateParsingException:簽字領域無效

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) 

找到東西從Oracle forum與此相關的沒有解決方案。

任何提示?

回答

4

PFX本身不是證書,而是密鑰庫。

爲了讓你有到PFX裝入到密鑰庫中,然後拿到證書的證書:

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

問候