pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Barry Zhao [Zhao]" <zhaz...@tibco-support.com>
Subject Re: Problem while decrypting a pdf file in Linux
Date Fri, 09 Jan 2015 09:59:58 GMT
Hi Maruan Sahyoun and team,

I change the dependence the V1.8.8.
First, I run my code:

PDDocument doc = PDDocument.load(originFile);
 if (doc.isEncrypted())
{
try
{
DecryptionMaterial dm = new StandardDecryptionMaterial("");
doc.openProtection(dm);
doc.setAllSecurityToBeRemoved(true);
}
catch (Exception cre) {
cre.printStackTrace();
}
}

I got the error info like:
org.apache.pdfbox.exceptions.WrappedIOException at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:375)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptString(SecurityHandler.java:577)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:429)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptDictionary(SecurityHandler.java:530)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:437)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptObject(SecurityHandler.java:403)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.proceedDecryption(SecurityHandler.java:221)
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.decryptDocument(StandardSecurityHandler.java:158)
at
org.apache.pdfbox.pdmodel.PDDocument.openProtection(PDDocument.java:1601)
at test1.main(test1.java:26) Caused by: javax.crypto.BadPaddingException:
Given final block not properly padded at
com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811) at
com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676) at
com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313) at
javax.crypto.Cipher.doFinal(Cipher.java:1970) at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
... 9 more

Then, I change my code 'load' function as below:
PDDocument doc = PDDocument.loadNonSeq(new File(originFile),null);

run my code again. I got the error info like before I post:
org.apache.pdfbox.exceptions.WrappedIOException
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:371)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptStream(SecurityHandler.java:475)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:433)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptObject(SecurityHandler.java:403)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.proceedDecryption(SecurityHandler.java:221)
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.decryptDocument(StandardSecurityHandler.java:158)
at org.apache.pdfbox.pdmodel.PDDocument.openProtection(PDDocument.java:1601)
at test1.main(test1.java:26)
Caused by: javax.crypto.IllegalBlockSizeException: Input length must be
multiple of 16 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:750)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
at javax.crypto.Cipher.doFinal(Cipher.java:1970)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
... 7 more

Any replies will be appreciated.
Thanks.

On Fri, Jan 9, 2015 at 4:55 PM, Barry Zhao [Zhao] <zhazhao@tibco-support.com
> wrote:

> Hi team,
>
> I use PDFBox V1.8.7.
> In Windows, it can work well.
> When I run my code in Linux, I got the exception below:
> java.io.IOException: javax.crypto.IllegalBlockSizeException: Input length
> must be multiple of 16 when decrypting with padded cipher
> at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:115)
> at javax.crypto.CipherInputStream.read(CipherInputStream.java:233)
> at javax.crypto.CipherInputStream.read(CipherInputStream.java:209)
> at
> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:316)
> at
> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptString(SecurityHandler.java:486)
> at
> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:386)
> at
> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decryptDictionary(SecurityHandler.java:466)
> at
> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.decrypt(SecurityHandler.java:394)
> 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:1595)
> at org.apache.pdfbox.pdmodel.PDDocument.decrypt(PDDocument.java:942)
>  .....etc.
> Caused by: javax.crypto.IllegalBlockSizeException: Input length must be
> multiple of 16 when decrypting with padded cipher
> at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:750)
> at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
> at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
> at javax.crypto.Cipher.doFinal(Cipher.java:1970)
> at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:112)
>
> And my code is :
> PDDocument doc = PDDocument.load(originFile);
>  if (doc.isEncrypted())
> {
> try
> {
> DecryptionMaterial dm = new StandardDecryptionMaterial("");
> doc.openProtection(dm);
> doc.setAllSecurityToBeRemoved(true);
> }
> catch (Exception cre) {
> cre.printStackTrace();
> }
> }
>
> And my jre version is 1.7.
> I use the attachment file to do the operation.
>
> Please help me to figure out the problem or do you guys have workarounds
> for this?
> Many thanks.
>
> Best wishes,
> Barry
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message