Hi. I tried to self sign the pdf file and get an exception.
Which version of bouncycastle should I use?
Can I find that version in the Internet?
Here is a detailed stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/bouncycastle/asn1/DEREncodable
at
com.itextpdf.text.pdf.PdfSignatureAppearance.getAppearance(PdfSignatureAppearance.java:409)
at
com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:951)
at
com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:897)
at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:194)
at Test2_QRCode.main(Test2_QRCode.java:221)
Caused by: java.lang.ClassNotFoundException:
org.bouncycastle.asn1.DEREncodable
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
(Test2_QRCode.java:221) it's a "stp.close();"
Here is a code of sign process:
try {
//creating the document "pdf.pdf".
...
//done.
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream("keystore.ks"), "password".toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias, "pasword".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader("pdf.pdf");
FileOutputStream fout = new FileOutputStream("signed.pdf");
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, 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);
stp.close();
} catch (Exception e) {
e.printStackTrace();
}
I attached the files bcprov-jdk15on-147.jar and bcpkix-jdk15on-147.jar to
the project. bcprov-jdk15on-147.jar have org/bouncycastle/asn1 package
inside. But doesn't have org/bouncycastle/asn1/DEREncodable. It
has org/bouncycastle/asn1/DEREncodableVector.
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
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