Hi Mathew, afaik the problem can not be solved, just circumvented. You get one hash from a PDF, after storing and reopening you get another hash. The raesons for this are not an iText issue and are already discussed on this list in detail.
So how to get around : Don't store and reopen the PDF before applying the signature. Or replace the signature in the stored PDF without using iText functionalities but low level file operations : Find the signature area in fuile, overwrite bytes x to y with the signature. Hope this helps. Andreas ----- Original Message ---- From: "[email protected]" <[email protected]> To: [email protected] Sent: Sat, March 20, 2010 4:07:26 PM Subject: Re: [iText-questions] PDFSignature - "Document has been altered since signature was applied" I am also facing the same issue could u please elaborate on how u resolved it. Regards Martin-- AndreiGosman wrote : Hi, I was a very big problem using iTextSharp and Aladdin eToken for signing PDF files. After I sign a pdf, Acrobat Reader gives the following message: "The document has been altered or corrupted since teh Certification was applied" Here is my code: Does someone know what is wrong? X509Certificate2 card = GetCertificate(certSerial); Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser(); Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(card.RawData) }; PdfReader reader = new PdfReader(fileToSign, Encoding.ASCII.GetBytes(ownerPassword)); PdfStamper stp = PdfStamper.CreateSignature(reader, new FileStream(signedFileName, FileMode.Create), '\0', null, true); PdfSignatureAppearance sap = stp.SignatureAppearance; sap.SignDate = signDate; sap.SetCrypto(null, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.Reason = reason; sap.Location = location; sap.Acro6Layers = true; sap.Render = PdfSignatureAppearance.SignatureRender.GraphicAndDescription; sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 250, 150), 1, null); sap.Render = PdfSignatureAppearance.SignatureRender.NameAndDescription; PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED); dic.Date = new PdfDate(sap.SignDate); dic.Name = PdfPKCS7.GetSubjectFields(chain[0]).GetField("CN"); if (sap.Reason != null) dic.Reason = sap.Reason; if (sap.Location != null) dic.Location = sap.Location; sap.CryptoDictionary = dic; int csize = 4000; Hashtable exc = new Hashtable(); exc[PdfName.CONTENTS] = csize * 2 +2; sap.PreClose(exc); //sap.PreClose(); HashAlgorithm sha = new SHA1CryptoServiceProvider(); Stream s = sap.RangeStream; int read = 0; byte[] buff = new byte[8192]; while ((read = s.Read(buff, 0, 8192)) > 0) { sha.TransformBlock(buff, 0, read, buff, 0); } sha.TransformFinalBlock(buff, 0, 0); byte[] pk = SignMsg(sha.Hash, card,false); byte[] outc = new byte[csize]; PdfDictionary dic2 = new PdfDictionary(); try { Array.Copy(pk, 0, outc, 0, pk.Length); dic2.Put(PdfName.CONTENTS, new PdfString(outc).SetHexWriting(true)); } finally { sap.Close(dic2); } Regards Andrei Gosman -- View this message in context: http://www.nabble.com/PDFSignature---%22Document-has-been-altered-since-signature-was-applied%22-tp20463953p20463953.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ iText-questions mailing list itext-questi...@list... https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php -- This message was sent on behalf of [email protected] at openSubscriber.com http://www.opensubscriber.com/message/[email protected]/10726249.html ------------------------------------------------------------------------------ Download IntelĀ® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
