Hi andyrobb18,

just listen what the reader says : 'the bytes are evil' (or something
like that...).

>From a quick look at the file I would guess you're missing the last zero
bytes in the signature field. Extend the array by two bytes and pad it
with '00'.
It should look like ...f961fc*00*>

Greetings,

Andreas
> Hi Michael
>
> Thanks for the reply - great to have confirmation that it should work. I've
> picked up the following code from the page indicated; I've used this example
> as I'm aware you can't sign SHA256 with WINCER. At the moment it signs the
> document, but the signature as invalid when I check it. See attached
>
> http://itext-general.2136553.n4.nabble.com/file/n4163557/signedX2.pdf
> signedX2.pdf 
>
> I'll keep plugging away, but if you can see anything obviously wrong with my
> code any help would be much appreciated. Fyi the pfx keystore was generated
> with java keytool and is set with a signing algorithm of SHA256withRSA.
>
> Cheers
> Andy
>
>               KeyStore ks = KeyStore.getInstance("pkcs12");
>               ks.load(new FileInputStream("test4.pfx"), 
> "key_pwd".toCharArray());
>               String alias = (String)ks.aliases().nextElement();
>               PrivateKey key = (PrivateKey)ks.getKey(alias, 
> "key_pwd".toCharArray());
>               Certificate[] chain = ks.getCertificateChain(alias);
>               PdfReader reader = new PdfReader("input2.pdf");
>               FileOutputStream fout = new FileOutputStream("signedZ9.pdf");
>               PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
>               PdfSignatureAppearance sap = stp.getSignatureAppearance();
>               sap.setCrypto(key, chain, null, 
> PdfSignatureAppearance.WINCER_SIGNED);
>               sap.setReason("TEST2");
>               sap.setLocation("Sydney");
>               // comment next line to have an invisible signature
>               sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, 
> null);
>               sap.setExternalDigest(null, new byte[20], null);
>               sap.preClose();
>               MessageDigest messageDigest = 
> MessageDigest.getInstance("SHA256");
>               byte buf[] = new byte[8192];
>               int n;
>               InputStream inp = sap.getRangeStream();
>               while ((n = inp.read(buf)) > 0) {
>                   messageDigest.update(buf, 0, n);
>               }
>               byte hash[] = messageDigest.digest();
>               PdfSigGenericPKCS sg = sap.getSigStandard();
>               PdfLiteral slit = (PdfLiteral)sg.get(PdfName.CONTENTS);
>               byte[] outc = new byte[(slit.getPosLength() - 2) / 2];
>               PdfPKCS7 sig = sg.getSigner();
>               sig.setExternalDigest(null, hash, null);
>               PdfDictionary dic = new PdfDictionary();
>               byte[] ssig = sig.getEncodedPKCS7();
>               System.arraycopy(ssig, 0, outc, 0, ssig.length);
>               dic.put(PdfName.CONTENTS, new 
> PdfString(outc).setHexWriting(true));
>               sap.close(dic);
>
> --
> View this message in context: 
> http://itext-general.2136553.n4.nabble.com/iText-SHA-256-signing-tp4125948p4163557.html
> Sent from the iText - General mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Cloud Services Checklist: Pricing and Packaging Optimization
> This white paper is intended to serve as a reference, checklist and point of 
> discussion for anyone considering optimizing the pricing and packaging model 
> of a cloud services business. Read Now!
> http://www.accelacomm.com/jaw/sfnl/114/51491232/
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> 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
>


-- 
Andreas Kühne 
phone: +49 177 293 24 97 
mailto: kue...@trustable.de

Trustable Ltd. Niederlassung Deutschland Ströverstr. 18 - 59427 Unna 
Amtsgericht Hamm HRB 5868

Directors Andreas Kühne, Heiko Veit

Company UK Company No: 5218868 Registered in England and Wales 

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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