Following this answer I'm trying to decrypt a pdf-document with pdfbox:
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."); }
This leads to
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 ...
The path is correct, so I don't know what's going on. Furthermore, if I have a look at the PDDocument.decrypt(String pw) method, I find this: This will decrypt a document. This method is provided for compatibility reasons only. User should use the new security layer instead and the openProtection method especially.
What does it mean? Could someone give an example how to decrypt a pdf-document correctly with pdfbox?