Hi Paulo,

I am using the iText-2.1.7.
It is the last release version, any idea of it? please help me.

Best regards,
Eric




On Tue, Sep 22, 2009 at 7:07 PM, Paulo Soares <psoa...@glintt.com> wrote:

> You are not using the latest iText version. The sign date is set in the
> constructor and can't be null unless you set it null.
>
> Paulo
>
> > -----Original Message-----
> > From: Eric Chow [mailto:eric...@gmail.com]
> > Sent: Tuesday, September 22, 2009 10:55 AM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] "External Signature with
> > SmartCard" in Java example!
> >
> > Hi all,
> >
> > I tried to use the following code, but some exception raised:
> >
> >
> > try {
> >             String configFile = "c:/esigntrust/config/pkcs11.cfg";
> >
> >             SunPKCS11 pkcs11 = new SunPKCS11(configFile);
> >             Security.addProvider(pkcs11);
> >
> >             char[] password = getPassword("Input", "Password");
> >
> >             KeyStore ks = KeyStore.getInstance("PKCS11");
> >             ks.load(null, password);
> >
> >             String alias = getAlias(ks, 1);
> >             // String alias = getSelQCAliasFromSM(configFile,
> > Constant.PIN);
> >
> >             X509Certificate cert =
> > getX509CertFormSM(configFile, password,
> >                     alias);
> >
> >             System.out.println(">>>" + cert.getSubjectDN().getName());
> >
> >
> >             PrivateKey privateKey = (PrivateKey)
> > ks.getKey(alias, password);
> >
> >             Certificate[] chain = ks.getCertificateChain(alias);
> >             System.out.println(chain[0].getPublicKey());
> >
> >             PdfReader reader = new PdfReader("doc/test1.pdf");
> >             FileOutputStream fout = new
> > FileOutputStream("doc/test1_signed.pdf");
> >             PdfStamper stp =
> > PdfStamper.createSignature(reader, fout, '\0');
> >             PdfSignatureAppearance sap = stp.getSignatureAppearance();
> >             sap.setCrypto(privateKey, chain, null,
> > PdfSignatureAppearance.SELF_SIGNED);
> >             sap.setReason("I'm the author");
> >             sap.setLocation("Lisbon");
> >             // comment next line to have an invisible signature
> >             sap.setVisibleSignature(new Rectangle(100, 100,
> > 200, 200), 1, null);
> >             sap.setExternalDigest(new byte[2048], null, "RSA");
> >             sap.preClose();
> >             PdfPKCS7 sig = sap.getSigStandard().getSigner();
> >             Signature sign = Signature.getInstance("SHA1withRSA");
> >             sign.initSign(privateKey);
> >             byte buf[] = new byte[8192];
> >             int n;
> >             java.io.InputStream inp = sap.getRangeStream();
> >             while ((n = inp.read(buf)) > 0) {
> >             sign.update(buf, 0, n);
> >             }
> >             sig.setExternalDigest(sign.sign(), null, "RSA");
> >             PdfDictionary dic = new PdfDictionary();
> >             dic.put(PdfName.CONTENTS, new
> > PdfString(sig.getEncodedPKCS1()).setHexWriting(true));
> >             sap.close(dic);
> >
> >
> >
> >         } catch(Exception e) {
> >             e.printStackTrace();
> >         }
> >
> >
> >
> > ===========================================
> > java.lang.NullPointerException
> >     at java.util.Calendar.setTime(Calendar.java:1070)
> >     at
> > com.lowagie.text.pdf.PdfSignatureAppearance.getSignDate(PdfSig
> > natureAppearance.java:841)
> >     at
> > com.lowagie.text.pdf.PdfSignatureAppearance.preClose(PdfSignat
> > ureAppearance.java:992)
> >     at
> > com.lowagie.text.pdf.PdfSignatureAppearance.preClose(PdfSignat
> > ureAppearance.java:920)
> >     at Sign.main(Sign.java:96)
> >
> >
> >
> >
> > Any suggestion?
> >
> > Best regards,
> > Eric
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Tue, Sep 22, 2009 at 5:45 PM, Eric Chow <eric...@gmail.com> wrote:
> >
> >
> >       Hello,
> >
> >       Any Java iText experts that have a simple example to
> > sign PDF with external signature approach?
> >
> >       Please give me a hand and show me a simple example.
> >
> >       Since I am new in iText, I can't totally understand the
> > example of iTextSharp. It is better to show me a Java code,
> > thank very much.
> >
> >       Best regards,
> >       Eric
> >
> >
> >
> >
> >
>
> 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.
>
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; 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&#45;12, 2009. Register now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php
> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
> You can also search the keywords list:
> http://1t3xt.info/tutorials/keywords/
>
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; 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&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to