Hello, I'm having an error trying to use the ITSAClient. I've 
used a lot of diferent url to get the timestamp but no one works.  I don't know 
what I'm doing wrong or where is the mistake.
My code is:

        public static void signPdfFile(string sourceDocument, string 
destinationPath, SysX509.X509Certificate2 signature, string keyPassword, string 
reason, string location, bool AddVisibleSign, int Pagina, int IzquierdaX, int  
IzquierdaY, int  DerechaX,int  DerechaY, string Contact, bool MultiSinght)
        {
            //X509Certificate2 signature = null;//Your X509Certificate2 
certificate instance here.
            string a = signature.PrivateKey.ToString();
            var akp = 
Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair(signature.PrivateKey).Private;
            IExternalSignature es = new PrivateKeySignature(akp, "SHA-256");

            // reader and stamper
            PdfReader reader = new PdfReader(sourceDocument);
            using (FileStream fout = new FileStream(destinationPath, 
FileMode.Create, FileAccess.ReadWrite))
            {
                using (PdfStamper stamper = PdfStamper.CreateSignature(reader, 
fout, '\0', null, MultiSinght))
                {
                    // appearance
                    PdfSignatureAppearance appearance = 
stamper.SignatureAppearance;
                    //appearance.Image = new iTextSharp.text.pdf.PdfImage();
                    if (reason != "")  appearance.Reason = reason;
                    if (location != "") appearance.Location = location;
                    if (Contact != "") appearance.Contact = Contact;

                    if (AddVisibleSign)
                        appearance.SetVisibleSignature(new 
Rectangle(IzquierdaX, IzquierdaY, DerechaX, DerechaY), Pagina, null);
                    // digital signature
                    Org.BouncyCastle.X509.X509CertificateParser cp = new 
Org.BouncyCastle.X509.X509CertificateParser();

                    Org.BouncyCastle.X509.X509Certificate[] chain = new[] { 
cp.ReadCertificate(signature.RawData) };

                    //string TSA_URL = 
"http://timestamp.globalsign.com/scripts/timstamp.dll";;
                    //String TSA_URL = "http://tsatest1.digistamp.com/TSA";;
                    String TSA_URL = 
"http://timestamp.verisign.com/scripts/timstamp.dll";; //Con este optengo algo 
válido
                    //String TSA_URL = 
"http://www.trustcenter.de/codesigning/timestamp";; //Con este optengo algo 
válido
                    //String TSA_URL = 
"http://timestamp.comodoca.com/authenticode";//Optengo algo pero no en el 
formato correcto.

                    //String TSA_URL = 
"http://www.edelweb.fr/cgi-bin/service-tsp";;
                    //String TSA_URL = 
"http://dse200.ncipher.com/TSS/HttpTspServer";;
                    //String TSA_URL = "http://tsa.safelayer.com:8093";;
                    //string TSA_URL = "http://www.cryptopro.ru/tsp/tsp.srf";;

                    ITSAClient TsaCliente = new TSAClientBouncyCastle(TSA_URL);
                    MakeSignature.SignDetached(appearance, es, chain, null, 
null, TsaCliente, 0, CryptoStandard.CMS);



                    stamper.Close();
                }
            }
        }

I get the error:
Message: DEF length 114 object truncated by 77
StackTrace:   en Org.BouncyCastle.Asn1.DefiniteLengthInputStream.ToArray() en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\srcbc\asn1\DefiniteLengthInputStream.cs:línea
 85
   en Org.BouncyCastle.Asn1.Asn1InputStream.BuildObject(Int32 tag, Int32 tagNo, 
Int32 length) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\srcbc\asn1\Asn1InputStream.cs:línea
 82
   en Org.BouncyCastle.Asn1.Asn1InputStream.ReadObject() en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\srcbc\asn1\Asn1InputStream.cs:línea
 207
   en Org.BouncyCastle.Tsp.TimeStampResponse.readTimeStampResp(Asn1InputStream 
input) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\srcbc\tsp\TimeStampResponse.cs:línea
 63
   en Org.BouncyCastle.Tsp.TimeStampResponse..ctor(Byte[] resp) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\srcbc\tsp\TimeStampResponse.cs:línea
 39
   en 
iTextSharp.text.pdf.security.TSAClientBouncyCastle.GetTimeStampToken(Byte[] 
imprint) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\iTextSharp\text\pdf\security\TSAClientBouncyCastle.cs:línea
 176
   en iTextSharp.text.pdf.security.PdfPKCS7.GetEncodedPKCS7(Byte[] 
secondDigest, DateTime signingTime, ITSAClient tsaClient, Byte[] ocsp, 
ICollection`1 crlBytes, CryptoStandard sigtype) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\iTextSharp\text\pdf\security\PdfPKCS7.cs:línea
 694
   en 
iTextSharp.text.pdf.security.MakeSignature.SignDetached(PdfSignatureAppearance 
sap, IExternalSignature externalSignature, ICollection`1 chain, ICollection`1 
crlList, IOcspClient ocspClient, ITSAClient tsaClient, Int32 estimatedSize, 
CryptoStandard sigtype) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\iTextSharp\text\pdf\security\MakeSignature.cs:línea
 127
   en FirmarPDF.PDF.signPdfFile(String sourceDocument, String destinationPath, 
X509Certificate2 signature, String keyPassword, String reason, String location, 
Boolean AddVisibleSign, Int32 Pagina, Int32 IzquierdaX, Int32 IzquierdaY, Int32 
DerechaX, Int32 DerechaY, String Contact, Boolean MultiSinght) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\PDF.cs:línea 73
   en SLCLABUtilPDF.Program.Main(String[] args) en 
C:\ProyectosAriza\SLCLABUtilPDF\SLCLABUtilPDF\Program.cs:línea 115

                                                        I would be very 
gratefull if you can help me.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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 via email to