Did you include the bouncy castle jar into your execution classpath ?
NoClassDefFoundError doesn't leave too much space for interpretation ...

Gretings

Andreas



----- Original Message ----
From: alberto calleja <lalbertocall...@gmail.com>
To: itext-questions@lists.sourceforge.net
Sent: Monday, May 18, 2009 4:21:01 PM
Subject: [iText-questions] problems in signing a pdf

Hi, i'd like to sign pdf document but i get this error:

ava.lang.NoClassDefFoundError: org/bouncycastle/asn1/DEREncodable
    at com.lowagie.text.pdf.PdfSignatureAppearance.getAppearance(Unknown Source)
    at com.lowagie.text.pdf.PdfSignatureAppearance.preClose(Unknown Source)
    at com.lowagie.text.pdf.PdfSignatureAppearance.preClose(Unknown Source)
    at com.lowagie.text.pdf.PdfStamper.close(Unknown Source)
    at prueba2.main(prueba2.java:45)
Exception in thread "main"

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;

import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfLiteral;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfPKCS7;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfSigGenericPKCS;
import com.lowagie.text.pdf.PdfSignatureAppearance;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfString;
import com.lowagie.text.pdf.codec.Base64.InputStream;
public class prueba2 {
public static void main (String [] args) throws Exception{
    KeyStore ks = KeyStore.getInstance("pkcs12");
    ks.load(new FileInputStream("c:/temp/sign.pfx"), "password".toCharArray());
    String alias = (String) ks.aliases().nextElement();
    PrivateKey key = (PrivateKey) ks.getKey(alias, "password".toCharArray());
    Certificate[] chain = ks.getCertificateChain(alias);
    PdfReader reader = new PdfReader("c:/temp/in.pdf");
    FileOutputStream fout = new FileOutputStream("c:/temp/out.pdf");
    PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
    PdfSignatureAppearance sap = stp.getSignatureAppearance();
    sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
    sap.setReason("iText");
    sap.setLocation("Espana");
    sap.setContact("Alberto");
    sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
    stp.close();
}
}

I have been doing several tests but I do not find where the mistake is.
Thanks

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
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/



------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
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