4

I use iText 5.5.0 and BouncyCastle bcprov-jdk15on-1.50 for digitally signing a pdf. It all works fine if I do not include a time stamp in the MakeSignature.signDetached method.

When I use the TSAClient specifying the TSAURL, my code gives me the error

java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable at MakeSignature.signDetached method

and my program gets terminated even though I handled exceptions.

I tried different versions of bouncycastle jars but I get the same error with difference in the classes not found.

I really need Timestamp included in the Signature. What should I do.

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
user3412670
  • 95
  • 1
  • 2
  • 6
  • What is `jdk15on`, and how are you including the jar? The Maven iText build includes artifacts that have the class you mentioned, and it also appears in all the BC versions I see listed on Central. – chrylis -cautiouslyoptimistic- Mar 19 '14 at 17:36
  • bcprov-jdk15on-1.50.jar is the latest version of BouncyCastle I found on internet. I am using 'add external jars' in eclipse to include the jar in my project. Yes that's true that the class ASN1Encodable is listed in all BC versions but in latest versions it is as an interface not a class. I am not sure that could cause the problem. – user3412670 Mar 19 '14 at 17:51
  • Please first try the version mentioned in the maven dependencies (currently 1.49). Bouncy Castle is known to do fundamental API changes in seemingly minor version changes. – mkl Mar 19 '14 at 20:30
  • Possible dupe of https://stackoverflow.com/questions/10391271/itext-bouncycastle-classnotfound-org-bouncycastle-asn1-derencodable-and-org-boun ? – rogerdpack Oct 25 '17 at 05:04

4 Answers4

6

You can check the dependency of itext 5.5 at the following URL.

http://mvnrepository.com/artifact/com.itextpdf/itextpdf/5.5.0

According to this page, corresponding version of bouncycastle for itext 5.5 is 1.49. I read on a page somewhere on internet that bouncycastle is heavily changing and it is often hard to find corresponding version of bouncycastle for a specific version of itext.

Fred
  • 61
  • 1
1

Please download the bcprov-jdk15on-150.jar (for JDK 1.5 - 1.7) file from below given link and add in your project to resolve java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable exception.

http://www.bouncycastle.org/latest_releases.html

find the appropriate jar file from the above link according to your JDK version.

  • 1
    With iText 5.5.x we only recommend to use BouncyCastle 1.49, that is the only version we use. BouncyCastle has been known to not respect Semantic Versioning and make incompatible API changes in minor version changes, as @mkl wrote above. That is why I am downvoting (Disclosure: I am QA Engineer @ iText Software). – Amedee Van Gasse Feb 22 '16 at 06:55
1

The recommended way of including iText in your project, is to use Maven. Maven will then solve the dependencies for you. I read that you use Eclipse, Eclipse has a very good Maven plugin.

Put this in your pom.xml:

<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>itextpdf</artifactId>
  <version>5.5.8</version>
</dependency> 

More info available at http://developers.itextpdf.com/itext-java

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
0

remove the folder bouncycastle (org/bouncycastle) from .m2, and run mvn clean compile to download dependencies

SSouhaieb
  • 248
  • 5
  • 16