java – pdfbox:试图解密PDF
发布时间:2020-12-14 05:33:13 所属栏目:Java 来源:网络整理
导读:以下 this answer我试图用pdfbox解密pdf文档: PDDocument pd = PDDocument.load(path);if(pd.isEncrypted()){ try { pd.decrypt(""); pd.setAllSecurityToBeRemoved(true); } catch (Exception e) { throw new Exception("The document is encrypted,and we
以下
this answer我试图用pdfbox解密pdf文档:
PDDocument pd = PDDocument.load(path); if(pd.isEncrypted()){ try { pd.decrypt(""); pd.setAllSecurityToBeRemoved(true); } catch (Exception e) { throw new Exception("The document is encrypted,and we can't decrypt it."); } 这导致 Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider at org.apache.pdfbox.pdmodel.PDDocument.openProtection(PDDocument.java:1601) at org.apache.pdfbox.pdmodel.PDDocument.decrypt(PDDocument.java:948) ... Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider ... 路径是正确的,所以我不知道发生了什么. 这是什么意思?有人可以举例说明如何使用pdfbox正确解密pdf文档? 解决方法
请参阅依赖关系列表:
https://pdfbox.apache.org/1.8/dependencies.html 你需要使用bouncycastle库. <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> 在当前版本(1.8.9)中确实已经不再采用decrypt()调用.使用 pd.openProtection(new StandardDecryptionMaterial("")); 代替. 附加建议:下载源代码包.你会发现很多例子可以帮助你进一步. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |