398927 (1) [Avatar] Offline
I am getting PKCS7 CMS block from services to attach signature on PDF. No any private key I have.
I used Bouncy castle Code to extract Info form PKCS7 bytes and I am able to get the info, but not able to attach the signature data to PDF using Itext.

I read the PDF "iText in Action 2nd Edition", Section:- 12.4.5 Creating the digest and signing externally, Still I am stuck on this part from so many days. Also the example given in this section are not working properly. Some methods are not their in PdfSignatureAppearance like getSigStandard() and setExternalDigest.

I m using itextpdf-5.5.3.jar in my code. I can provide BouncyCastle code of extract signature from PKCS7 bytes.

CMSSignedData cmsSignedData = new CMSSignedData(decodedBytes);
			ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(decodedBytes)); 
			ContentInfo contentInfo = ContentInfo.getInstance(aIn.readObject());
	        CMSSignedData cms = new CMSSignedData(contentInfo);
	        JcaX509CertificateConverter converter = new JcaX509CertificateConverter();
	        Store store = cms.getCertificates();
	        SignerInformationStore signersInfoStore = cms.getSignerInfos();
	        Collection<SignerInformation> signers = signersInfoStore.getSigners();
	        //logger.debug("signers num [" + signers.size() + "]");
	        X509Certificate[] chain = new X509Certificate[2];
	        int i=0;
	        for (SignerInformation si : signers) {
	            SignerId sid = si.getSID();
	            Collection<X509CertificateHolder> holders = store.getMatches(null);
	            System.out.println("Signer Id #######"+sid.getIssuer());
	            //logger.debug("holders num [" + holders.size() + "]");
	            for (X509CertificateHolder certholder : holders) {
	                X509Certificate cert = converter.getCertificate(certholder);
	                System.out.println("Cert #######"+cert.getType());
	                //logger.debug("Issuer [" + cert.getPublicKey() + "]");
	                //CertificateInfo certInfo = util.parse(cert);

Thanks in advance. Please assist.