3

I've recently had to upgrade to iText, but I'm having problems getting setEncryption to work. I'm using iText 5.5.6.

document = new Document(PageSize.LETTER, 36, 36, 72, 72);
writer = PdfWriter.getInstance(document, out);
writer.setEncryption(null, OWNER_PASSWORD.getBytes(), writer.AllowPrinting|writer.AllowCopy, PdfWriter.STANDARD_ENCRYPTION_128);

gets me the following error:

java.lang.SecurityException: class "org.bouncycastle.asn1.ASN1Primitive"'s signer information does not match signer information of other classes in the same package

At first I thought I might be using the wrong JAR file for bouncycastle. I was on 1.52, when apparently iText 5.5.0 wants 1.49, but even using older JAR files, I get the same results.

I've tried both bcprov-jdk15on-1.49 and bcprov-ext-jdk15on-1.49, so I'm really not sure what I'm doing wrong at this point.

Beacon80
  • 349
  • 1
  • 4
  • 14
  • 1
    The exception text indicates that you have multiple versions of BouncyCastle on your class path. Please remove all but one. – mkl Aug 11 '15 at 05:37
  • As far as I can tell, I only have the one. If I remove it, Tomcat doesn't report any errors, but instead of the PDF, I get prompted to save a file called "reportgenerator" which is just the exception report for a NoClassDefFoundError about bouncycastle's ASN1Primitive. – Beacon80 Aug 11 '15 at 16:48
  • That shows that you have (at least) two versions of BouncyCastle and removed the one iText requires. Most likely the remaining versions are older, maybe from before 1.47, the big ugly API cut. – mkl Aug 11 '15 at 20:02
  • Took me a while to find where the old version was hiding, but that worked. Thanks. – Beacon80 Aug 12 '15 at 20:18

1 Answers1

1

It turns out I had a second Bouncy Castle library hiding. Thanks mkl.

Beacon80
  • 349
  • 1
  • 4
  • 14