CertificateFactory fact = CertificateFactory.getInstance("X.509"); FileInputStream is = new FileInputStream("./lib/license/felice.pem"); result = (X509Certificate) fact.generateCertificate(is);
X509Certificate result = null; try { //InputStream in = X509Certificate.class.getResourceAsStream("classpath:META-INF/xxxxx.RSA"); InputStream in = new ClassPathResource("META-INF/xxxxxx.RSA").getInputStream(); byte[] buffer = in.readAllBytes(); in.close(); //Corresponding class of signed_data is CMSSignedData CMSSignedData signature = new CMSSignedData(buffer); Store cs = signature.getCertificates(); SignerInformationStore signers = signature.getSignerInfos(); Collection c = signers.getSigners(); Iterator it = c.iterator(); //the following array will contain the content of xml document //byte[] data = null; while (it.hasNext()) { SignerInformation signer = (SignerInformation) it.next(); Collection certCollection = cs.getMatches(signer.getSID()); Iterator certIt = certCollection.iterator(); X509CertificateHolder cert = (X509CertificateHolder) certIt.next();
CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); InputStream in2 = new ByteArrayInputStream(cert.getEncoded()); result = (X509Certificate) certFactory.generateCertificate(in2);