It may happen if your pdf has javascript or anything else that might
change the appearance after the pdf is signed. Remove all that before
signing.

Paulo 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of [EMAIL PROTECTED]
> Sent: Wednesday, January 16, 2008 11:11 AM
> To: [email protected]
> Subject: [iText-questions] error 4000 "unrecognized PDF 
> content" PDF/SigQ
> 
> 
> Hi,
> 
> I have made a test to sign a pdf wih itext:
> the sample at 
> http://itextpdf.sourceforge.net/howtosign.html#howtosign seems to
> work fine but when I open the signed PDF with Acrobat 8.1 
> (not the reader)
> I can see an error when of conformance to  PDF/SigQ
> 
> I have linked error dialog box and the signed pdf
> 
> thanks in advance for your help
> 
> here the code :
> 
>          KeyStore ks;
>          ks = KeyStore.getInstance("pkcs12");
>          ks.load(new FileInputStream(fileKey), 
> fileKeyPassword.toCharArray());
>          String alias = (String) ks.aliases().nextElement();
>          PrivateKey key;
>          key = (PrivateKey) ks.getKey(alias, 
> fileKeyPassword.toCharArray());
>          Certificate[] chain = ks.getCertificateChain(alias);
> 
>          File fileToSign = new File(fname);
>          PdfReader pdfReader = new 
> PdfReader(fileToSign.getAbsolutePath());
> 
>          FileOutputStream outputFile = new FileOutputStream(fileToSign
>                .getParent()
>                + File.separator + fileToSign.getName() + 
> "_signed2.pdf");
> 
>          // Creation du tampon de signature
>          PdfStamper pdfStamper;
>          pdfStamper = PdfStamper.createSignature(pdfReader, 
> outputFile, '\0');
>          PdfSignatureAppearance sap = 
> pdfStamper.getSignatureAppearance();
>          sap.setCrypto(key, chain, null, 
> PdfSignatureAppearance.WINCER_SIGNED);
>          sap.setReason("I'm the author");
>          sap.setLocation("France");
> 
>          //sap.setVisibleSignature(new Rectangle(10, 10, 50, 
> 30), 1, null);
> 
>          sap.setExternalDigest(new byte[512], new byte[20], "RSA");
>          sap.preClose();
>          MessageDigest messageDigest = 
> MessageDigest.getInstance("SHA1");
>          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();
>          Signature sign = Signature.getInstance("SHA1withRSA");
>          sign.initSign(key);
>          sign.update(hash);
>          sig.setExternalDigest(sign.sign(), hash, "RSA");
>          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);
> 
> 
> 


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to