尝试在 PDFBox 中解密时出现异常
Exception while trying to decrypt in PDFBox
在尝试使用 PDFBox 解密加密的 PDF 时,我遇到了异常 -
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.pdfbox.pdfmodel.encryption.StandardSecurityHandler.computeEncryptedKey
at org.apache.pdfbox.pdfmodel.encryption.StandardSecurityHandler.computeUserPassword
我使用的代码是
PDDocument doc = PDDocument.load(file);
if (doc.isEncrypted()) {
StandardDecryptionMaterial dm = new StandardDecryptionMaterial(password);
doc.openProtection(dm);
}
异常发生在openProtection方法。
我也尝试了doc.decrypt方法,但结果相同。
我的 maven 包含
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.13</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
<version>1.44</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15</artifactId>
<version>1.44</version>
</dependency>
Java版本为1.7
我尝试了 PDFBox/bouncyCastle (1.8.7/1.46) 的多个版本 - 但仍然存在此异常。
如果我尝试 qpdf --decrypt 事先解密文件并且它运行良好。但是当我尝试使用代码解密时,由于之前的异常而失败。
我在 Spring 引导应用程序中使用它 - 这可能是一个原因吗?
如果有人能指出我可能的解决方案,我将不胜感激。
谢谢你,Tilman Hausherr。
我试用了 PDFBox 2.0.7,它运行良好。
在尝试使用 PDFBox 解密加密的 PDF 时,我遇到了异常 -
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.pdfbox.pdfmodel.encryption.StandardSecurityHandler.computeEncryptedKey
at org.apache.pdfbox.pdfmodel.encryption.StandardSecurityHandler.computeUserPassword
我使用的代码是
PDDocument doc = PDDocument.load(file);
if (doc.isEncrypted()) {
StandardDecryptionMaterial dm = new StandardDecryptionMaterial(password);
doc.openProtection(dm);
}
异常发生在openProtection方法。 我也尝试了doc.decrypt方法,但结果相同。
我的 maven 包含
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.13</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
<version>1.44</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15</artifactId>
<version>1.44</version>
</dependency>
Java版本为1.7
我尝试了 PDFBox/bouncyCastle (1.8.7/1.46) 的多个版本 - 但仍然存在此异常。
如果我尝试 qpdf --decrypt 事先解密文件并且它运行良好。但是当我尝试使用代码解密时,由于之前的异常而失败。
我在 Spring 引导应用程序中使用它 - 这可能是一个原因吗?
如果有人能指出我可能的解决方案,我将不胜感激。
谢谢你,Tilman Hausherr。
我试用了 PDFBox 2.0.7,它运行良好。