iText setEncryption error

2019-07-07 00:35发布

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.

1条回答
做自己的国王
2楼-- · 2019-07-07 01:08

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

查看更多
登录 后发表回答