Quantcast

Adding signature image to pdf

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding signature image to pdf

Edward Cooke

Hello all, I’m pretty new to iTextSharp and I’m trying to add the image of a signature, it’s a simple windows image, to a PDF signature field.

When I go to close the stamper, I get a null reference exception, and the pdf is not written to the memory stream. All the sample’s I’ve found include setting a certificate when doing the image. (I’d prefer not to have to do this yet.) This code is in C#. Here’s my code.

 

                                   using (System.IO.MemoryStream output = new System.IO.MemoryStream())
                                   {
                                            PdfReader reader = new PdfReader(Request.PhysicalApplicationPath + "\\SamplePDFs\\" + document.Name);
                                            PdfStamper stamper = PdfStamper.CreateSignature(readeroutput'\0');
                                            PdfSignatureAppearance appearance = stamper.SignatureAppearance;
 
                                            System.Drawing.Image signatureImage = null;
 
                                            //convert the signature into a .NET image
                                            Topaz.SigPlusNET sigpad = new Topaz.SigPlusNET();
                                            sigpad.SetSigCompressionMode(0); //no compression.
                                            sigpad.SetImageXSize(400);
                                            sigpad.SetImageYSize(100);
                                            sigpad.SetImagePenWidth(1);
                                            sigpad.SetJustifyMode(5);
                                            sigpad.SetSigString(Request["signature"]);
                                            signatureImage = sigpad.GetSigImage();
 
                                            stamper.FormFlattening = true;
 
                                            //set the signature appearance info
                                            appearance.SetVisibleSignature("Signature1");
                                            appearance.Reason = "It's Personal";
                                            appearance.Location = "A location";
                                            appearance.SignatureGraphic = Image.GetInstance(signatureImageBaseColor.WHITE);
                                            appearance.Acro6Layers = true;
                                            appearance.Render = PdfSignatureAppearance.SignatureRender.Graphic;
 
                                            //write the stamped pdf to the memory stream
                                            stamper.Close();
 
                                            //set the browser content type and attachment. write the memory stream to the browser
                                            Response.ContentType = "Application/pdf";
                                            Response.AddHeader("Content-Disposition""attachment;filename=\"" + document.Name + "\"");
 
                                            // write the memory stream to the browser
                                            Response.BinaryWrite(output.GetBuffer());
                                            Response.Flush();
                                            Response.End();
                                            return null;
                                   }

 

Does anybody have any thoughts? Is the certificate piece required? I was hoping to not need to put it on there. If it is required, does the root certificate have to be trusted by the receiver of the document, or is there some kind of adobe self-signed cert that would work? How does adobe acrobat do the encryption/signing if it’s required? Or could it be an internal CA that the outside world doesn’t know about?

 

Thanks in advance,

-Ed-


logo Edward Cooke
Programmer II, Information Systems
+1 801-325-6143 tel
+1 801-898-5940 cell
[hidden email]
http://www.macu.com

Banner
fb tw





***Confidentiality and Security Notice: This message and any attachments are intended only for the use of the individual or entity to which it is addressed and may contain confidential and/or privileged information. If you are not the intended recipient you are hereby notified that any dissemination, copying, or distribution of this message, or attachments, is strictly prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete it from your computer. Do not send sensitive data via unencrypted email as it may be intercepted in transit***



------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy
to use, easy to manage, easy to install, easy to extend.
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding signature image to pdf

iText mailing list
On 12/08/2011 19:23, Edward Cooke wrote:

Hello all, I’m pretty new to iTextSharp and I’m trying to add the image of a signature, it’s a simple windows image, to a PDF signature field.

When I go to close the stamper, I get a null reference exception, and the pdf is not written to the memory stream. All the sample’s I’ve found include setting a certificate when doing the image. (I’d prefer not to have to do this yet.)

I'm not sure if I understand your question.

Do you want to create a PDF that is NOT digitally signed, but that shows the image of a signature?
Or do you want to create a PDF this IS digitally signed, and shows an image of a signature in the signature field?

I don't understand how you would expect a PDF to be digitally signed without a Private key and Public Certificate.
See http://www.slideshare.net/blowagie/pdf-digital-signatures

If adding an image of a signature is all you want, and if you don't require the PDF to be digitally signed, why would you use a signature field?

Are you sure you understand the concept of digital signatures?
Digital signatures have nothing to do with scanned signatures stored as an image.

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy
to use, easy to manage, easy to install, easy to extend.
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding signature image to pdf

Edward Cooke

I’m looking to display the image of a signature, without being digitally signed. But then I want the signature image to be removed/invalidated when the pdf changes. And I’m really new to these signatures in the pdf, so I might not understand them. I was under the impression you can store the image of a signature in the signature field, that would be marked invalid if the pdf document changes without the use of any digital signatures. Am I missing something?

 


logo Edward Cooke
Programmer II, Information Systems
+1 801-325-6143 tel
+1 801-898-5940 cell
[hidden email]
http://www.macu.com

Banner
fb tw




From: 1T3XT BVBA [mailto:[hidden email]]
Sent: Friday, August 12, 2011 1:00 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Adding signature image to pdf

 

On 12/08/2011 19:23, Edward Cooke wrote:

Hello all, I’m pretty new to iTextSharp and I’m trying to add the image of a signature, it’s a simple windows image, to a PDF signature field.

When I go to close the stamper, I get a null reference exception, and the pdf is not written to the memory stream. All the sample’s I’ve found include setting a certificate when doing the image. (I’d prefer not to have to do this yet.)

I'm not sure if I understand your question.

Do you want to create a PDF that is NOT digitally signed, but that shows the image of a signature?
Or do you want to create a PDF this IS digitally signed, and shows an image of a signature in the signature field?

I don't understand how you would expect a PDF to be digitally signed without a Private key and Public Certificate.
See http://www.slideshare.net/blowagie/pdf-digital-signatures

If adding an image of a signature is all you want, and if you don't require the PDF to be digitally signed, why would you use a signature field?

Are you sure you understand the concept of digital signatures?
Digital signatures have nothing to do with scanned signatures stored as an image.


***Confidentiality and Security Notice: This message and any attachments are intended only for the use of the individual or entity to which it is addressed and may contain confidential and/or privileged information. If you are not the intended recipient you are hereby notified that any dissemination, copying, or distribution of this message, or attachments, is strictly prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete it from your computer. Do not send sensitive data via unencrypted email as it may be intercepted in transit***



------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy
to use, easy to manage, easy to install, easy to extend.
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding signature image to pdf

iText mailing list
On 12/08/2011 21:03, Edward Cooke wrote:
I’m looking to display the image of a signature, without being digitally signed. But then I want the signature image to be removed/invalidated when the pdf changes. And I’m really new to these signatures in the pdf, so I might not understand them. I was under the impression you can store the image of a signature in the signature field, that would be marked invalid if the pdf document changes without the use of any digital signatures. Am I missing something?
You're most certainly missing something.

You can display the image of a signature, without a PDF being digitally signed. But if you want the PDF to indicate a problem if the PDF is changed, it needs to be digitally signed. You can store an image in a signature field, but the signature field MUST also contain a hash of the contents of the PDF that is encrypted using a private key; otherwise how do you expect that a change can be detected?

All of this is explained in great detail in chapter 12 of the book "iText in Action - 2nd Edition", but you should start by reading http://www.slideshare.net/blowagie/pdf-digital-signatures and if that's to difficult, please read: http://en.wikipedia.org/wiki/Digital_signatures

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy
to use, easy to manage, easy to install, easy to extend.
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding signature image to pdf

Edward Cooke

Ok, thanks. That answered my questions.

 


logo Edward Cooke
Programmer II, Information Systems
+1 801-325-6143 tel
+1 801-898-5940 cell
[hidden email]
http://www.macu.com

Banner
fb tw




From: 1T3XT BVBA [mailto:[hidden email]]
Sent: Friday, August 12, 2011 1:16 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Adding signature image to pdf

 

On 12/08/2011 21:03, Edward Cooke wrote:

I’m looking to display the image of a signature, without being digitally signed. But then I want the signature image to be removed/invalidated when the pdf changes. And I’m really new to these signatures in the pdf, so I might not understand them. I was under the impression you can store the image of a signature in the signature field, that would be marked invalid if the pdf document changes without the use of any digital signatures. Am I missing something?

You're most certainly missing something.

You can display the image of a signature, without a PDF being digitally signed. But if you want the PDF to indicate a problem if the PDF is changed, it needs to be digitally signed. You can store an image in a signature field, but the signature field MUST also contain a hash of the contents of the PDF that is encrypted using a private key; otherwise how do you expect that a change can be detected?

All of this is explained in great detail in chapter 12 of the book "iText in Action - 2nd Edition", but you should start by reading http://www.slideshare.net/blowagie/pdf-digital-signatures and if that's to difficult, please read: http://en.wikipedia.org/wiki/Digital_signatures


***Confidentiality and Security Notice: This message and any attachments are intended only for the use of the individual or entity to which it is addressed and may contain confidential and/or privileged information. If you are not the intended recipient you are hereby notified that any dissemination, copying, or distribution of this message, or attachments, is strictly prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete it from your computer. Do not send sensitive data via unencrypted email as it may be intercepted in transit***



------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy
to use, easy to manage, easy to install, easy to extend.
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

~RE: Adding signature image to pdf

Edward Cooke
In reply to this post by Edward Cooke

Hi again, I’ve been banging my head against the wall trying to sign the document with a certificate and itextsharp. I’ve tried copying your code on http://itextpdf.sourceforge.net/howtosign.html#signextitextsharp2 in the Sign by card section at the bottom, changing it to pull a certificate from the store instead of by a card. It gets the public and private keys and appears to be working correctly. Inside of adobe it shows the correct certificate being applied, but it is telling me it’s an invalid signatre, it’s saying that the byte range is invalid. Any thoughts?

 

 

Here’s the code that I’m using:

                                   using (MemoryStream output = new MemoryStream())
                                   {

                                            X509Store x509Store = new X509Store(StoreName.MyStoreLocation.LocalMachine);

                                            x509Store.Open(OpenFlags.ReadOnly);

                                            //read out the first cert

                                            X509Certificate2 x509Cert = x509Store.Certificates[1]; //first cert, this is just POC stuff, you will want to change this

                                            OrgX509.X509CertificateParser cp = new OrgX509.X509CertificateParser();

                                            OrgX509.X509Certificate[] chain = new OrgX509.X509Certificate[] { cp.ReadCertificate(x509Cert.RawData) };

                                            PdfReader reader = new PdfReader("C:\\testpdf.pdf");

                                            PdfStamper stamper = PdfStamper.CreateSignature(readeroutput'\0'"c:\\temp\\temppdf.pdf"false);

                                            PdfSignatureAppearance sap = stamper.SignatureAppearance;

                                            sap.SetVisibleSignature(new Rectangle(100100300200), 1null);

                                            sap.SignDate = DateTime.Now;

                                            sap.SetCrypto(nullchainnullnull);

                                            sap.Reason = "I like to sign";

                                            sap.Location = "Universe";

                                            sap.Acro6Layers = true;

                                            sap.Render = PdfSignatureAppearance.SignatureRender.NameAndDescription;

                                            PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKMSPdfName.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;

                                            Dictionary<PdfNameint> exc = new Dictionary<PdfNameint>();//in your code this is a hashtable. But in actuality it is a dictionary

                                            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(buff08192)) > 0)

                                            {

                                                    sha.TransformBlock(buff0readbuff0);

                                           }

                                            sha.TransformFinalBlock(buff00);

                                            byte[] pk = SignMsg(sha.Hashx509Certfalse);

                                            byte[] outc = new byte[csize];

                                            PdfDictionary dic2 = new PdfDictionary();

                                            Array.Copy(pk0outc0pk.Length);

                                            dic2.Put(PdfName.CONTENTSnew PdfString(outc).SetHexWriting(true));

                                            sap.Close(dic2);

 

 

                                            stamper.Close();

                                   }

 

                 static public byte[] SignMsg(Byte[] msgX509Certificate2 signerCertbool detached)
                 {
                          //  Place message in a ContentInfo object.
                          //  This is required to build a SignedCms object.
                          ContentInfo contentInfo = new ContentInfo(msg);
 
                          //  Instantiate SignedCms object with the ContentInfo above.
                          //  Has default SubjectIdentifierType IssuerAndSerialNumber.
                          SignedCms signedCms = new SignedCms(contentInfodetached);
 
                          //  Formulate a CmsSigner object for the signer.
                          CmsSigner cmsSigner = new CmsSigner(signerCert);
 
                          // Include the following line if the top certificate in the
                          // smartcard is not in the trusted list.
                          cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;
 
                          //  Sign the CMS/PKCS #7 message. The second argument is
                          //  needed to ask for the pin.
                          signedCms.ComputeSignature(cmsSignerfalse);
 
                          //  Encode the CMS/PKCS #7 message.
                          return signedCms.Encode();
                 }

 

Thanks in advance,

Ed

From: 1T3XT BVBA [mailto:[hidden email]]
Sent: Friday, August 12, 2011 1:16 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Adding signature image to pdf

 

On 12/08/2011 21:03, Edward Cooke wrote:

I’m looking to display the image of a signature, without being digitally signed. But then I want the signature image to be removed/invalidated when the pdf changes. And I’m really new to these signatures in the pdf, so I might not understand them. I was under the impression you can store the image of a signature in the signature field, that would be marked invalid if the pdf document changes without the use of any digital signatures. Am I missing something?

You're most certainly missing something.

You can display the image of a signature, without a PDF being digitally signed. But if you want the PDF to indicate a problem if the PDF is changed, it needs to be digitally signed. You can store an image in a signature field, but the signature field MUST also contain a hash of the contents of the PDF that is encrypted using a private key; otherwise how do you expect that a change can be detected?

All of this is explained in great detail in chapter 12 of the book "iText in Action - 2nd Edition", but you should start by reading http://www.slideshare.net/blowagie/pdf-digital-signatures and if that's to difficult, please read: http://en.wikipedia.org/wiki/Digital_signatures



------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2

_______________________________________________
iText-questions mailing list
[hidden email]
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
mkl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ~RE: Adding signature image to pdf

mkl
Edward,
Edward Cooke wrote
I've been banging my head against the wall trying to sign the document with a certificate and itextsharp. I've tried copying your code on http://itextpdf.sourceforge.net/howtosign.html#signextitextsharp2 in the Sign by card section at the bottom, changing it to pull a certificate from the store instead of by a card. It gets the public and private keys and appears to be working correctly. Inside of adobe it shows the correct certificate being applied, but it is telling me it's an invalid signatre, it's saying that the byte range is invalid. Any thoughts?
Even though I'm not working with the .Net versions (and, thus, cannot easily reproduce your tests), I (and others) might help if you provided a sample document signed with your code. Seeing what exactly is wrong in the document often gives good hints when searching the culprit.

Regards,   Michael.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

~RE: ~RE: Adding signature image to pdf

Edward Cooke
In reply to this post by Edward Cooke
I was able to get it working late last night by changing the temp file path to null when calling the PdfStamper.CreateSignature method.
Thanks for your help.

Old line
                                            PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0', "c:\\temp\\temppdf.pdf", false);

New line
                                            PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0', null, false); //changed the temp path to be null and it works correctly

What's weird, is that it had full rights and access to the path of the file that was in there, but would break the PDF when it was in there. Another side note is that when using the temp path, the pdf is about 30k bigger. I've attached a working and broken copy for you if you want to look at it?
Here is the code that is working, maybe it will help someone out in the future with pulling certificates from the windows certificate store.

                public byte[] SignPdf(string pdf, byte[] password)
                {
                        using (MemoryStream output = new MemoryStream())
                        {
                                X509Store x509Store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                                x509Store.Open(OpenFlags.ReadOnly);
                                //read out the first cert
                                X509Certificate2 x509Cert =
                                        x509Store.Certificates.Find(
                                                X509FindType.FindByThumbprint,
                                                System.Configuration.ConfigurationManager.AppSettings["PDFCertificateThumbprint"],
                                                false)[0];
                                OrgX509.X509CertificateParser cp = new OrgX509.X509CertificateParser();
                                OrgX509.X509Certificate[] chain = new OrgX509.X509Certificate[] { cp.ReadCertificate(x509Cert.RawData) };

                                PdfReader reader = new PdfReader(pdf);
                                PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0', null, false); //changed the temp path to be null and it works correctly
                                //stamper.SetEncryption(null,
                                //    password,
                                //    PdfWriter.ALLOW_PRINTING |
                                //    PdfWriter.ALLOW_COPY |
                                //    PdfWriter.ALLOW_SCREENREADERS,
                                //    PdfWriter.ENCRYPTION_AES_256);

                                PdfSignatureAppearance sap = stamper.SignatureAppearance;

                                sap.SetVisibleSignature(new Rectangle(1, 1, 1, 1), 1, "SigField");
                                sap.SignDate = DateTime.Now;
                                sap.SetCrypto(null, chain, null, null);
                                sap.Reason = "I like to sign";
                                sap.Location = "Universe";
                                sap.Acro6Layers = true;
                                sap.Render = PdfSignatureAppearance.SignatureRender.Description;
                                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;
                                Dictionary<PdfName, int> exc = new Dictionary<PdfName, int>();
                                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);
                                byte[] pk = SignMsg(sha.Hash, x509Cert, false);

                                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);


                                stamper.Close();

                                return output.GetBuffer();
                        }
                }

                public byte[] SignMsg(Byte[] msg, X509Certificate2 signerCert, bool detached)
                {
                        //  Place message in a ContentInfo object.
                        //  This is required to build a SignedCms object.
                        ContentInfo contentInfo = new ContentInfo(msg);

                        //  Instantiate SignedCms object with the ContentInfo above.
                        //  Has default SubjectIdentifierType IssuerAndSerialNumber.
                        SignedCms signedCms = new SignedCms(contentInfo, detached);

                        //  Formulate a CmsSigner object for the signer.
                        CmsSigner cmsSigner = new CmsSigner(signerCert);

                        // Include the following line if the top certificate in the
                        // smartcard is not in the trusted list.
                        cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;

                        //  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.
                        return signedCms.Encode();
                }


-----Original Message-----
From: mkl [mailto:[hidden email]]
Sent: Wednesday, August 17, 2011 3:27 AM
To: [hidden email]
Subject: Re: [iText-questions] ~RE: Adding signature image to pdf

Edward,

Edward Cooke wrote:
> I've been banging my head against the wall trying to sign the document
> with a certificate and itextsharp. I've tried copying your code on
> http://itextpdf.sourceforge.net/howtosign.html#signextitextsharp2 in
> the Sign by card section at the bottom, changing it to pull a
> certificate from the store instead of by a card. It gets the public
> and private keys and appears to be working correctly. Inside of adobe
> it shows the correct certificate being applied, but it is telling me
> it's an invalid signatre, it's saying that the byte range is invalid. Any thoughts?

Even though I'm not working with the .Net versions (and, thus, cannot easily reproduce your tests), I (and others) might help if you provided a sample document signed with your code. Seeing what exactly is wrong in the document often gives good hints when searching the culprit.

Regards,   Michael.

--
View this message in context: http://itext-general.2136553.n4.nabble.com/Adding-signature-image-to-pdf-tp3740010p3749483.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
iText-questions mailing list
[hidden email]
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





------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
iText-questions mailing list
[hidden email]
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
Loading...