Hi Paulo.

Thanks for your information. Finally i solve my problems with blank signature generation. I continue in geenration a signature from pdf document and add in blank signature. Now I can not validate the signature. If I edit the pdf document with my editor it's very unusual the value of byte range becosue appear with
ByteRange [0 13581 13597 10 18529 6 18550 3406 ]

I work with next code :

PdfReader reader = new PdfReader("blank.pdf");
FileOutputStream fout = new FileOutputStream("signed.pdf");

PRAcroForm form = reader.getAcroForm();
if (form == null){
System.out.println("This document has no fields.");
return true;
}

PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0', null, true);
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setVisibleSignature("Signature1");
sap.setLayer2Text("This is some custom made text.");
sap.setReason( "Reason") ;

PdfDictionary dic = new PdfDictionary();
dic.put(PdfName.FT, PdfName.SIG);
dic.put(PdfName.FILTER, new PdfName("Adobe.PPKLite"));
dic.put(PdfName.SUBFILTER, new PdfName("adbe.pkcs7.sha1"));
sap.setCryptoDictionary(dic);
HashMap exc = new HashMap();
exc.put(PdfName.CONTENTS, new Integer(0x133A));
exc.put(PdfName.NAME, new Integer(0xF));
exc.put(PdfName.REASON, new Integer(0x10));
sap.preClose(exc);

MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
byte buf[] = new byte[8192];
int n;
InputStream inp = sap.getRangeStream();
while ((n = inp.read(buf)) > 0) {
        messageDigest.update(buf, 0, n);
}

byte hash[] = messageDigest.digest();

// Call to my property pkcs7 generation function
byte[] ssig = generatePKCS7( hash);
byte[] outc = new byte[ssig.length];
System.arraycopy(ssig, 0, outc, 0, ssig.length);
PdfDictionary dic2= new PdfDictionary();

dic2.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));
dic2.put(PdfName.NAME, new PdfString("homer simpson") );
dic2.put(PdfName.REASON, new PdfString("Reason") );
sap.close(dic2);

return true ;


I reserve space to include the Contents, Name and Reason but I don't undertand the value of byte ange. I suposo that this is the error to I can not validate the signature.
Can you give some information that helps me to sign OK ?


A lot of thanks in advance.



From: "Paulo Soares" <[EMAIL PROTECTED]>
Reply-To: "Paulo Soares" <[EMAIL PROTECTED]>
To: "Juan Sanchez" <[EMAIL PROTECTED]>,<itext-questions@lists.sourceforge.net>
Subject: Re: [iText-questions] Add signatures in a existing blank signature
Date: Tue, 9 Aug 2005 10:03:40 +0100

For the blank signature get the code from PdfAcroForm. You'll get a
PdfFormField to add in PdfStamper.addAnnotation(). There's no
PdfStamper.createSignature() or PdfSignatureAppearance here. I think I've
already answered this with an example in the mailing list.

As for signing you have all the information needed, maybe you're not using
the right filter or generating the right hash, that depends on what you use
to produce the PKCS#7.

----- Original Message -----
From: "Juan Sanchez" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <itext-questions@lists.sourceforge.net>
Sent: Tuesday, August 09, 2005 7:51 AM
Subject: Re: [iText-questions] Add signatures in a existing blank signature


>
> Good morning Paulo.
>
> I want to insert in a existing pdf file a blank signature becouse this pdf
> will reside in a server and other persons will insert his signature in
this
> blank signature.
> I work in two codes, one for insert the blank signature and other to
insert
> a signature in this existent pdf with blank signature generated.
>
> In the first code (insert a blank signature) fails when I  call to close
> functions of pdfstamper.
> Inthe second code, I put the appearance in the blank signature but fails
> when I built to put the pkcs7 in the content. Pdf is generated but is not
a
> valid :-( , I suposo that I put in the content field an incorrect value.
>
> All samples or information will be helpful.
>
>
> >From: "Paulo Soares" <[EMAIL PROTECTED]>
> >Reply-To: "Paulo Soares" <[EMAIL PROTECTED]>
> >To: "Juan Sanchez"
> ><[EMAIL PROTECTED]>,<itext-questions@lists.sourceforge.net>
> >Subject: Re: [iText-questions] Add signatures in a existing blank
signature
> >Date: Mon, 8 Aug 2005 16:40:56 +0100
> >
> >We probably should rewind this thread and start all over again, I'm
> >confused. What exactly are you trying to do? How would you do that with
> >Acrobat?
> >
> >Best Regards,
> >Paulo Soares
> >
> >----- Original Message -----
> >From: "Juan Sanchez" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>; <itext-questions@lists.sourceforge.net>
> >Sent: Monday, August 08, 2005 11:36 AM
> >Subject: Re: [iText-questions] Add signatures in a existing blank
signature
> >
> >
> > >
> > > Hi Paulo.
> > >
> > > I read the PDF reference to nderstand the signature dictionary
entries.
> > > I test inserting next code in the sample to define the filter :
> > >
> > >                 ...
> > >                 PdfStamper stp = PdfStamper.createSignature(reader,
> >fout,
> > > '\0', null, true);
> > >         PdfSignatureAppearance sap = stp.getSignatureAppearance();
> > >
> > >                 // begin new coe added
> > >         PdfDictionary dic = new PdfDictionary();
> > >         dic.put(PdfName.FT, PdfName.SIG);
> > >         dic.put(PdfName.FILTER, new PdfName("Adobe.PPKMS"));
> > > sap.setCryptoDictionary(dic);
> > >                //end new cod added
> > >
> > >                ...
> > >                stp.close();
> > >
> > >
> > > But the result is the same.Falis when I call the stp.close() function.
> > >
> > > I generate a pdf with one blank signature only with acrobat and I
don't
> >find
> > > any filter value in the pdf when I edit the file.
> > >
> > > I can see, in the samples, that all insert the FT, FILTER and
SUBFILTER
> > > fields first and then insert the CONTENTS. But in a blank signature
> >don't
> > > exist Content to put.
> > >
> > > Can you help me to find my error or the part of code that is necessary
> >to
> > > build a blank signature correctly.
> > >
> > > Note : I follow the same steps to built the pdf that in signature.java
> > > sample that use PdfAcroForm bject. In this sample new document is
> >created
> > > and following the code implementation I search when the filter is put
> >but
> >i
> > > have not found it.
> > >
> > >
> > > >From: "Paulo Soares" <[EMAIL PROTECTED]>
> > > >Reply-To: "Paulo Soares" <[EMAIL PROTECTED]>
> > > >To: "Juan Sanchez"
> > > ><[EMAIL PROTECTED]>,<itext-questions@lists.sourceforge.net>
> > > >Subject: Re: [iText-questions] Add signatures in a existing blank
> >signature
> > > >Date: Fri, 5 Aug 2005 11:25:53 +0100
> > > >
> > > >You didn't define the signature filter (PdfName.ADOBE_PPKLITE for
> >example).
> > > >You should read the PDF Reference to have a notion on how signatures
> >work.
> > > >Start with the examples in howtosign and replace one thing at a time.
> > > >
> > > >----- Original Message -----
> > > >From: "Juan Sanchez" <[EMAIL PROTECTED]>
> > > >To: <[EMAIL PROTECTED]>; <itext-questions@lists.sourceforge.net>
> > > >Sent: Friday, August 05, 2005 8:52 AM
> > > >Subject: Re: [iText-questions] Add signatures in a existing blank
> >signature
> > > >
> > > >
> > > > >
> > > > > Hi Paulo.
> > > > >
> > > > > Here the output :
> > > > >
> > > > > Before stp.close
> > > > >
> > > > > Error
> > > > >
> > > > > java.lang.IllegalArgumentException: Unknown filter: null
> > > > > java.lang.IllegalArgumentException: Unknown filter: null
> > > > > at
> > > > >
> > >
> >
>com.lowagie.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance
> >.
> > > >java:778)
> > > > > at
> > > > >
> > >
> >
>com.lowagie.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance
> >.
> > > >java:717)
> > > > > at com.lowagie.text.pdf.PdfStamper.close(PdfStamper.java:200)
> > > > > at
> >com.lowagie.examples.forms.FormSignature.main(FormSignature.java:125)
> > > > >
> > > > >
> > > > > >From: "Paulo Soares" <[EMAIL PROTECTED]>
> > > > > >Reply-To: "Paulo Soares" <[EMAIL PROTECTED]>
> > > > > >To: "Juan Sanchez"
> > > > > ><[EMAIL PROTECTED]>,<itext-questions@lists.sourceforge.net>
> > > > > >Subject: Re: [iText-questions] Add signatures in a existing blank
> > > >signature
> > > > > >Date: Thu, 4 Aug 2005 13:27:59 +0100
> > > > > >
> > > > > >What's the stack trace?
> > > > > >
> > > > > >----- Original Message -----
> > > > > >From: "Juan Sanchez" <[EMAIL PROTECTED]>
> > > > > >To: <[EMAIL PROTECTED]>;
<itext-questions@lists.sourceforge.net>
> > > > > >Sent: Thursday, August 04, 2005 10:07 AM
> > > > > >Subject: Re: [iText-questions] Add signatures in a existing blank
> > > >signature
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > Hi Paulo
> > > > > > >
> > > > > > > Another question about blank signatures.
> > > > > > > I test with the code sample from the question
[iText-questions]
> > > >Adding
> > > > > >Blank
> > > > > > > Signature Field gives problem , but the program return me an
> >error
> > > >in
> > > > > >the
> > > > > > > close function  stp.close();
> > > > > > > As you commented I put the same code used in the
> > > >AcroForm.AddSignature
> > > > > >usgn
> > > > > > > the addAnnotation from PdfStamper.
> > > > > > >
> > > > > > > What's the problem  ?
> > > > > > >
> > > > > > >   PdfReader reader = new PdfReader("blank3.pdf");
> > > > > > >     FileOutputStream fout = new
FileOutputStream("signed.pdf");
> > > > > > >
> > > > > > >     int lx = 50 ;
> > > > > > >     int ly = 50 ;
> > > > > > >     int ux = 100 ;
> > > > > > >     int uy = 100 ;
> > > > > > >
> > > > > > >                PdfStamper stp =
> >PdfStamper.createSignature(reader,
> > > >fout,
> > > > > > > '\0', null, true);
> > > > > > > PdfSignatureAppearance sap = stp.getSignatureAppearance();
> > > > > > >
> > > > > > >     PdfWriter writer = stp.getWriter();
> > > > > > >     PdfFormField sig = PdfFormField.createSignature(writer);
> > > > > > >
> > > > > > >     stp.addAnnotation(sig, 1);
> > > > > > >     sig.setWidget(new Rectangle(lx, ly, ux, uy),
> > > > > > > PdfAnnotation.HIGHLIGHT_INVERT);
> > > > > > >     sig.setFlags(PdfAnnotation.FLAGS_PRINT);
> > > > > > >     sig.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g"));
> > > > > > >     sig.setFieldName("SignatureBLANK");
> > > > > > >     sig.setPage();
> > > > > > >                 sig.setMKBorderColor(java.awt.Color.black);
> > > > > > > sig.setMKBackgroundColor(java.awt.Color.white)
;
> > > > > > >
> > > > > > >         PdfContentByte cb = writer.getDirectContent();
> > > > > > > PdfAppearance tp = cb.createAppearance(ux-lx, uy-ly);
> > > > > > >         tp.setGrayFill(1.0f);
> > > > > > >         tp.rectangle(0, 0, ux-lx, uy-ly);
> > > > > > >         tp.fill();
> > > > > > >         tp.setGrayStroke(0);
> > > > > > >         tp.setLineWidth(1);
> > > > > > >         tp.rectangle(0.5f, 0.5f, ux-lx - 0.5f, uy - ly -
0.5f);
> > > > > > >         tp.closePathStroke();
> > > > > > >         tp.saveState();
> > > > > > >         tp.rectangle(1, 1, ux-lx - 2, uy - ly - 2);
> > > > > > >         tp.clip();
> > > > > > >         tp.newPath();
> > > > > > >         tp.restoreState();
> > > > > > >         sig.setAppearance(PdfAnnotation.APPEARANCE_NORMAL,
tp);
> > > > > > >
> > > > > > >         stp.addAnnotation(sig, 1);
> > > > > > >         stp.close();
> > > > > > >
> > > > > > > Best regards in advance.
> > > > > > >
> > > > > > >
> > > > > > > >From: "Paulo Soares" <[EMAIL PROTECTED]>
> > > > > > > >Reply-To: "Paulo Soares" <[EMAIL PROTECTED]>
> > > > > > > >To: "Juan Sanchez"
> > > > > > > ><[EMAIL PROTECTED]>,<itext-questions@lists.sourceforge.net>
> > > > > > > >Subject: Re: [iText-questions] Add signatures in a existing
> >blank
> > > > > >signature
> > > > > > > >Date: Wed, 3 Aug 2005 16:41:34 +0100
> > > > > > > >
> > > > > > > >Signatures must be done one at a time, that's the way PDFs
> >work.
> >Do
> > > >the
> > > > > > > >next
> > > > > > > >signatures in append mode (as you did in your code). You can
> >have
> > > > > >external
> > > > > > > >signatures or even a full external PKCS#7, see the examples.
> > > > > > > >
> > > > > > > >----- Original Message -----
> > > > > > > >From: "Juan Sanchez" <[EMAIL PROTECTED]>
> > > > > > > >To: <[EMAIL PROTECTED]>;
> ><itext-questions@lists.sourceforge.net>
> > > > > > > >Sent: Wednesday, August 03, 2005 3:27 PM
> > > > > > > >Subject: Re: [iText-questions] Add signatures in a existing
> >blank
> > > > > >signature
> > > > > > > >
> > > > > > > >
> > > > > > > > >
> > > > > > > > > Hi Paulo.
> > > > > > > > >
> > > > > > > > > After execute the next code , in the pdf document (that
> >contain
> > > >3
> > > > > >blank
> > > > > > > > > signatures) only appear 1 signed and the others continue
> > > >empties.
> > > > > > > > > What is the problem ? is it necessary to close document
> > > >everytime
> > > >?
> > > > > > > > >
> > > > > > > > >     PdfReader reader = new PdfReader("blank_3.pdf");
> > > > > > > > >     FileOutputStream fout = new
> >FileOutputStream("signed.pdf");
> > > > > > > > >
> > > > > > > > >         PRAcroForm form = reader.getAcroForm();
> > > > > > > > >         if (form == null){
> > > > > > > > >             System.out.println("This document has no
> >fields.");
> > > > > > > > >             return;
> > > > > > > > >         }
> > > > > > > > >
> > > > > > > > >         // prepare keyStore
> > > > > > > > >         KeyStore ks = KeyStore.getInstance("pkcs12");
> > > > > > > > >         ks.load(new FileInputStream("myCert.p12"),
> > > > > > > >"mypass".toCharArray());
> > > > > > > > > String alias = (String)ks.aliases().nextElement();
> > > > > > > > >         PrivateKey key = (PrivateKey)ks.getKey(alias,
> > > > > > > > > "mypass".toCharArray());
> > > > > > > > >         Certificate[] chain =
ks.getCertificateChain(alias);
> > > > > > > > >
> > > > > > > > >         PdfStamper stp =
PdfStamper.createSignature(reader,
> > > >fout,
> > > > > >'\0',
> > > > > > > > > null, true);
> > > > > > > > >         AcroFields af = stp.getAcroFields();
> > > > > > > > >         ArrayList names = af.getBlankSignatureNames();
> > > > > > > > >         for (int k = 0; k < names.size(); ++k) {
> > > > > > > > > String name = (String)names.get(k);
> > > > > > > > > System.out.println("Signature name: " + name);
> > > > > > > > >
> > > > > > > > > PdfSignatureAppearance sap = stp.getSignatureAppearance();
> > > > > > > > > sap.setCrypto(key, chain, null,
> > > > > >PdfSignatureAppearance.WINCER_SIGNED);
> > > > > > > > > sap.setReason("MyReasons");
> > > > > > > > > sap.setLocation("MyLocation");
> > > > > > > > > sap.setVisibleSignature(name);
> > > > > > > > >         }
> > > > > > > > >         stp.close();
> > > > > > > > >     }
> > > > > > > > >     catch(Exception e ){
> > > > > > > > >     System.out.println("\n\t" + e.toString());
> > > > > > > > >     }
> > > > > > > > >     }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Regards.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > >From: "Paulo Soares" <[EMAIL PROTECTED]>
> > > > > > > > > >Reply-To: "Paulo Soares" <[EMAIL PROTECTED]>
> > > > > > > > > >To: "Juan Sanchez"
> > > > > > > > >
> > ><[EMAIL PROTECTED]>,<itext-questions@lists.sourceforge.net>
> > > > > > > > > >Subject: Re: [iText-questions] Add signatures in a
existing
> > > >blank
> > > > > > > >signature
> > > > > > > > > >Date: Wed, 3 Aug 2005 11:09:01 +0100
> > > > > > > > > >
> > > > > > > > > >See http://itextpdf.sf.net/howtosign.html. To sign an
> >existing
> > > > > >field
> > > > > > > >use
> > > > > > > > > >PdfSignaturaAppearance.setVisibleSignature(String).
> > > > > > > > > >
> > > > > > > > > >----- Original Message -----
> > > > > > > > > >From: "Juan Sanchez" <[EMAIL PROTECTED]>
> > > > > > > > > >To: <itext-questions@lists.sourceforge.net>
> > > > > > > > > >Sent: Wednesday, August 03, 2005 9:38 AM
> > > > > > > > > >Subject: [iText-questions] Add signatures in a existing
> >blank
> > > > > >signature
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > > Hi.
> > > > > > > > > > >
> > > > > > > > > > > I want to insert a signature in a blank signature
> >created
> > > > > > > >previously.
> > > > > > > > > > > Is there some example that it can help me ?
> > > > > > > > > > >
> > > > > > > > > > > Regards.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > >_________________________________________________________________ > > > > > > > > > > > Don't just search. Find. Check out the new MSN Search!
> > > > > > > > > > > http://search.msn.com/
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> -------------------------------------------------------
> > > > > > > > > > > SF.Net email is sponsored by: Discover Easy Linux
> >Migration
> > > > > > > >Strategies
> > > > > > > > > > > from IBM. Find simple to follow Roadmaps,
> >straightforward
> > > > > >articles,
> > > > > > > > > > > informative Webcasts and more! Get everything you need
> >to
> > > >get
> > > >up
> > > > > >to
> > > > > > > > > > > speed, fast.
> > > > > >http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> > > > > > > > > > > _______________________________________________
> > > > > > > > > > > iText-questions mailing list
> > > > > > > > > > > iText-questions@lists.sourceforge.net
> > > > > > > > > > >
> >https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >-------------------------------------------------------
> > > > > > > > > >SF.Net email is sponsored by: Discover Easy Linux
Migration
> > > > > >Strategies
> > > > > > > > > >from IBM. Find simple to follow Roadmaps, straightforward
> > > >articles,
> > > > > > > > > >informative Webcasts and more! Get everything you need to
> >get
> > > >up
> > > >to
> > > > > > > > > >speed, fast.
> > > > > >http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> > > > > > > > > >_______________________________________________
> > > > > > > > > >iText-questions mailing list
> > > > > > > > > >iText-questions@lists.sourceforge.net
> > > > > > > > >
> > >https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > > > > > >
> > > > > > > > >
> > > >_________________________________________________________________
> > > > > > > > > Don't just search. Find. Check out the new MSN Search!
> > > > > > > > >
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >-------------------------------------------------------
> > > > > > > >SF.Net email is sponsored by: Discover Easy Linux Migration
> > > >Strategies
> > > > > > > >from IBM. Find simple to follow Roadmaps, straightforward
> >articles,
> > > > > > > >informative Webcasts and more! Get everything you need to get
> >up
> >to
> > > > > > > >speed, fast.
> > > >http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> > > > > > > >_______________________________________________
> > > > > > > >iText-questions mailing list
> > > > > > > >iText-questions@lists.sourceforge.net
> > > > > > > >https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > > > >
> > > > > > >
> >_________________________________________________________________
> > > > > > > Express yourself instantly with MSN Messenger! Download
today -
> >it's
> > > > > >FREE!
> > > > > > >
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> > > > > > >
> > > > > >
> > > > >
> > > > > _________________________________________________________________
> > > > > Don't just search. Find. Check out the new MSN Search!
> > > > > http://search.msn.click-url.com/go/onm00200636ave/direct/01/
> > > > >
> > > >
> > >
> > > _________________________________________________________________
> > > Express yourself instantly with MSN Messenger! Download today it's
FREE!
> > > http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> > >
> >
>
> _________________________________________________________________
> Don't just search. Find. Check out the new MSN Search!
> http://search.msn.com/
>



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to