代码之家  ›  专栏  ›  技术社区  ›  Raju

尝试在PDFBox中解密时出现异常

  •  0
  • Raju  · 技术社区  · 8 年前

    在尝试使用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);
    }
    

    我也试过了,博士。解密方法,但结果相同。

    我的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

    我在一个Spring Boot应用程序中使用它-这可能是一个原因吗?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Raju    8 年前

    谢谢你,蒂尔曼·豪泽尔。

    我试过PDFBox 2.0.7,效果很好。