解密時,在過去,我曾嘗試解密使用PDFBox的使用下面的代碼的PDF文件:BadPaddingException與PDFBox的
if (doc.isEncrypted()){
doc.openProtection(new StandardDecryptionMaterial(password));
doc.setAllSecurityToBeRemoved(true);
}
(請注意,我不使用doc.decrypt(password)
因爲the Javadoc for decrypt()說openProtection()應改爲使用,雖然爲什麼它不僅僅是被棄用的)。
無論如何,這已經運行良好很長一段時間。但是,最近我似乎得到以下例外:
java.io.IOException: javax.crypto.BadPaddingException: Given final block not properly padded
at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:118)
at javax.crypto.CipherInputStream.read(CipherInputStream.java:236)
at javax.crypto.CipherInputStream.read(CipherInputStream.java:212)
at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:316)
at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptStream(SecurityHandler.java:421)
at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:390)
at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptObject(SecurityHandler.java:365)
at org.apache.pdfbox.pdmodel.encryption.SecurityHandler.proceedDecryption(SecurityHandler.java:196)
at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.decryptDocument(StandardSecurityHandler.java:158)
at org.apache.pdfbox.pdmodel.PDDocument.openProtection(PDDocument.java:1598)
<Stack trace continues with my call to openProtection()>
我該如何解決這個問題?
1.8.8 out :-) –