Hello,

I want to sign a PDF with the following code:

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
System.out.println(ks.getProvider());
ks.load(new FileInputStream("C:\\j2sdk1.4.2_05\\bin\\keystore3.ks"), 
pass.toCharArray());

String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias, pass.toCharArray());
                
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader("c:\\Antrag.pdf");
FileOutputStream fout = new FileOutputStream("c:\\signed.pdf");
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.VERISIGN_SIGNED);
sap.setReason("I'm the author");
sap.setLocation("Saarbrücken");
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
sap.setCertified(true);
stp.close();

If I use a self signed Certificate the code run with no problem. But if I 
import my Versign Certificate in the keystore I get the follow Message. 

java.lang.NullPointerException
        at 
com.lowagie.text.pdf.PdfSignatureAppearance.getAppearance(PdfSignatureAppearance.java:395)
        at 
com.lowagie.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:902)
        at 
com.lowagie.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:847)
        at com.lowagie.text.pdf.PdfStamper.close(PdfStamper.java:175)
        at de.jens.kelkel.PDFSignature.main(PDFSignature.java:89)
Exception in thread "main"

Have anybody a solution fort hat problem??

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to