|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Co-Sign Adobe 8 OK but 9 corruptedI am from Brazil and I need a help...
please, to point the mistake... When do I co-sign a document PDF and do I open in the version of the adobe 8 says that is valid the 2 signatures but when do I open the 9 says that the first this corrupted, what done this miss? thank you very much, Alexandre Zanella. System.IO.MemoryStream streamAssinado = new System.IO.MemoryStream(); X509Certificate2 card = assinatura.Get(); 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(dados); PdfStamper stp = PdfStamper.CreateSignature(reader, streamAssinado, '\0', null, true); //Propriedades da assinatura PdfSignatureAppearance sap = stp.SignatureAppearance; //Habilita a visibilidade da assinatura. //sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 300, 200), 1, null); sap.SignDate = assinatura.DataAssinatura; sap.SetCrypto(null, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.Reason = assinatura.Motivo; sap.Location = assinatura.Local; sap.Contact = assinatura.Contato; sap.Acro6Layers = true; sap.Render = PdfSignatureAppearance.SignatureRender.NameAndDescription; //sap.CertificationLevel = (PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS); PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKMS, PdfName.ADBE_PKCS7_SHA1); 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); 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); // Sign the message with the private key of the signer. // Place message in a ContentInfo object. // This is required to build a SignedCms object. ContentInfo contentInfo = new ContentInfo(sha.Hash); // Instantiate SignedCms object with the ContentInfo above. // Has default SubjectIdentifierType IssuerAndSerialNumber. SignedCms signedCms = new SignedCms(contentInfo, false); // Formulate a CmsSigner object for the signer. CmsSigner cmsSigner = new CmsSigner(card); // Include the following line if the top certificate in the // smartcard is not in the trusted list. cmsSigner.IncludeOption = (X509IncludeOption)incluirCertificado; // Sign the CMS/PKCS #7 message. The second argument is // needed to ask for the pin. signedCms.ComputeSignature(cmsSigner, false); // Encode the CMS/PKCS #7 message. byte[] pk = signedCms.Encode(); byte[] outc = new byte[csize]; PdfDictionary dic2 = new PdfDictionary(); Array.Copy(pk, 0, outc, 0, pk.Length); dic2.Put(PdfName.CONTENTS, new PdfString(outc).SetHexWriting(true)); sap.Close(dic2); dadosAssinados = streamAssinado.ToArray(); |
|
|
Re: Co-Sign Adobe 8 OK but 9 corrupted |
|
|
Re: Co-Sign Adobe 8 OK but 9 corruptedThere's nothing to worry about, this is a change of behavior in Acrobat 9.
In Acrobat 9 only the last signature is marked as valid but the other ones are ok although marked invalid because you added more to the document after signing it. If you extract the first revision the signature will show up as valid. Paulo ----- Original Message ----- From: "alzs" <dados@...> To: <itextsharp-questions@...> Sent: Thursday, September 17, 2009 6:50 PM Subject: [itextsharp-questions] Co-Sign Adobe 8 OK but 9 corrupted I am from Brazil and I need a help... please, to point the mistake... When do I co-sign a document PDF and do I open in the version of the adobe 8 says that is valid the 2 signatures but when do I open the 9 says that the first this corrupted, what done this miss? thank you very much, Alexandre Zanella. System.IO.MemoryStream streamAssinado = new System.IO.MemoryStream(); X509Certificate2 card = assinatura.Get(); 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(dados); PdfStamper stp = PdfStamper.CreateSignature(reader, streamAssinado, '\0', null, true); //Propriedades da assinatura PdfSignatureAppearance sap = stp.SignatureAppearance; //Habilita a visibilidade da assinatura. //sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 300, 200), 1, null); sap.SignDate = assinatura.DataAssinatura; sap.SetCrypto(null, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.Reason = assinatura.Motivo; sap.Location = assinatura.Local; sap.Contact = assinatura.Contato; sap.Acro6Layers = true; sap.Render = PdfSignatureAppearance.SignatureRender.NameAndDescription; //sap.CertificationLevel = (PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS); PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKMS, PdfName.ADBE_PKCS7_SHA1); 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); 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); // Sign the message with the private key of the signer. // Place message in a ContentInfo object. // This is required to build a SignedCms object. ContentInfo contentInfo = new ContentInfo(sha.Hash); // Instantiate SignedCms object with the ContentInfo above. // Has default SubjectIdentifierType IssuerAndSerialNumber. SignedCms signedCms = new SignedCms(contentInfo, false); // Formulate a CmsSigner object for the signer. CmsSigner cmsSigner = new CmsSigner(card); // Include the following line if the top certificate in the // smartcard is not in the trusted list. cmsSigner.IncludeOption = (X509IncludeOption)incluirCertificado; // Sign the CMS/PKCS #7 message. The second argument is // needed to ask for the pin. signedCms.ComputeSignature(cmsSigner, false); // Encode the CMS/PKCS #7 message. byte[] pk = signedCms.Encode(); byte[] outc = new byte[csize]; PdfDictionary dic2 = new PdfDictionary(); Array.Copy(pk, 0, outc, 0, pk.Length); dic2.Put(PdfName.CONTENTS, new PdfString(outc).SetHexWriting(true)); sap.Close(dic2); dadosAssinados = streamAssinado.ToArray(); ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ itextsharp-questions mailing list itextsharp-questions@... https://lists.sourceforge.net/lists/listinfo/itextsharp-questions |
|
|
Re: Co-Sign Adobe 8 OK but 9 corruptedOk Paulo, but when the signature is made by Acrobat both are marked as valid. Is there some way to sign like Acrobat?
|
| Free embeddable forum powered by Nabble | Forum Help |