Hi,
Thank you very much.
Problem is now solved
Andrei Gosman
Paulo Soares-3 wrote:
>
> See http://itextpdf.sourceforge.net/howtosign.html#signextitextsharp2.
>
> Paulo
>
> ________________________________________
> From: AndreiGosman [EMAIL PROTECTED]
> Sent: Wednesday, November 12, 2008 4:33 PM
> To: [email protected]
> Subject: [iText-questions] PDFSignature - "Document has been altered since
> signature was applied"
>
> 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
>
> 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 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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php
>
--
View this message in context:
http://www.nabble.com/PDFSignature---%22Document-has-been-altered-since-signature-was-applied%22-tp20463953p20476730.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
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php