2014-11-17 29 views
0

解密時,在過去,我曾嘗試解密使用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()> 

我該如何解決這個問題?

+0

1.8.8 out :-) –

回答

1

這是a known issue,它似乎是作爲Java更新的結果而引入的。在撰寫本文時,對此進行的修復將在1.8.8版本中進行審查,因此只需升級到版本1.8.8或更高版本,此問題就會消失。

+0

是的,我們正在研究這個。請嘗試1.8.8快照;如果它不起作用,請將您的文件附加到PDFBOX-2469問題中。 https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox/1.8.8-SNAPSHOT/ –

+0

@Tilman我使用jarbox的pdfbox-app版本,但是據我所知告訴,快照僅以非捆綁形式出現。可惜,因爲我會有興趣嘗試它。 – Thunderforge

+0

不確定你的意思 - 快照pdfbox-app與發佈版本相同。在某些情況下,你可能需要在你的類路徑中使用jai_imageio和/或jbig2。 –