signed jar파일에서 인증서(certificate)를 읽어온다.
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);
if( null != result)
break;
//CMSProcessable sc = signature.getSignedContent();
//data = (byte[]) sc.getContent();
}
} catch (CertificateException | CMSException | IOException e) {
log.error(“”,e);
}
return result;