Hi,
I have succesfully signed ,also in append mode, a pdf file with visible
acrofield PdfSignatureApparence
Know Id want to make a form to show certificate information like
validity,issuer etc,like adobe acrobat reader certificate information.
All it works on adobe acrobat reader and the sign is valid and detailed.
I have seen that this is possible to extract certificate information with
the code:

PdfPKCS7 pk = af.verifySignature(name);
Calendar cal = pk.getSignDate();


but on the first line of code I receive the error

"SHA256 MessageDigest not available"

Can anyone help me?

below the code used to sign:

public static void signDetached(String src, String dest, boolean certified,
boolean graphic,int x,int y)
            throws Exception {
            PdfReader pdfReader= new PdfReader(src);
            FileOutputStream fout = new FileOutputStream(dest);
            PdfStamper stp = PdfStamper.createSignature(pdfReader, fout, '\0',
null, true);
            
            PdfSignatureAppearance sap = stp.getSignatureAppearance();
            
            stp.setFullCompression();
            sap.setAcro6Layers(true);
           
//sap.setRender(PdfSignatureAppearance.SignatureRenderNameAndDescription);
            sap.setReason("Reason");
            sap.setSignDate(new GregorianCalendar());
            y = y-32;//imposta l'angolo alto siistro del rettangolo come angolo
basso sinistro del cursore
            //sig.setWidget(new Rectangle(x, y, x+72, y+50), null);
            sap.setVisibleSignature(new Rectangle(x, y, x+72, y+50), 1, null);
            sap.setLocation("Location");
            sap.setExternalDigest(new byte[513], new byte[20], "RSA");
            //sap.setContact(signerContact);
            //sap.setImage(signatureImage);

            KeyStore ke; // Well opened and initiated KeyStore
            Security.addProvider(new BouncyCastleProvider());  
            String path = "D:\\Keystore\\myidentitykeystore.jks";
            String keystore_password = "mypass";
            String key_password = "mypass";
            KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
                ks.load(new FileInputStream(path), 
keystore_password.toCharArray());
            String alias = "myalias";
            PrivateKey pk = (PrivateKey)ks.getKey(alias,
key_password.toCharArray());
            Certificate[] chain = ks.getCertificateChain(alias);
            sap.setCrypto(null, chain, null, null);

            PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE,          
  
PdfName.ADBE_PKCS7_DETACHED);
            dic.setDate(new PdfDate(sap.getSignDate()));
            dic.setName("myname");

            if (sap.getReason() != null) dic.setReason(sap.getReason());
            if (sap.getLocation() != null) dic.setLocation(sap.getLocation());
            sap.setCryptoDictionary(dic);

            int csize = 4000;
            HashMap exc = new HashMap();
            exc.put(PdfName.CONTENTS, new Integer(csize * 2 + 2));
            sap.preClose(exc);

            CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
            generator.addSigner(pk, (X509Certificate)chain[0],
CMSSignedDataGenerator.DIGEST_SHA256);
            ArrayList list = new ArrayList();
            for (int i = 0; i < chain.length; i++) list.add(chain[i]);

            CertStore chainStore = CertStore.getInstance("Collection", new
CollectionCertStoreParameters(list));
            generator.addCertificatesAndCRLs(chainStore);
            CMSProcessable content = new CMSProcessableRange(sap);
            CMSSignedData signedData = null;

            signedData = generator.generate(content, false, "BC");

            byte[] pk2 = signedData.getEncoded();
            byte[] outc = new byte[csize];
            PdfDictionary dic2 = new PdfDictionary();
            System.arraycopy(pk2, 0, outc, 0, pk2.length);
            dic2.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));

            sap.close(dic2);



--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/itext-5-05-pkcs7-detached-sha256-bouncy-sign-problem-tp3343671p3343671.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to