You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Barry Zhao [Zhao]" <zh...@tibco-support.com> on 2014/12/30 03:15:07 UTC

PDFBOX-2469 still have problem while decrypting a pdf file

Hi team,

I see that the PDFBox has staged out new release 1.8.8, so I just try to
use the new version.
When I decrypt a PDF file which is decrypted, I got the exception bellow:

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 Testpdf10.main(Testpdf10.java:44)
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:1969)
at
org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
... 9 more

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();
}
}

I use the attachment file to do the operation.


I found this
http://stackoverflow.com/questions/26963718/badpaddingexception-when-decrypting-with-pdfbox
in
stackoverflow.
I tried by the advices and it still not work.
So I post this email to you. Hope to get your answer.

Best wishes,
Barry

Re: PDFBOX-2469 still have problem while decrypting a pdf file

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,

Am 30.12.2014 um 18:29 schrieb Thomas Chojecki:
> Am Tue, 30 Dec 2014 10:08:14 +0100
> schrieb Tilman Hausherr <TH...@t-online.de>:
>
>> Hi,
> Hi Tilman,
>
>> ...
>>
>> And then there's the second one in PDFBOX-2469, that doesn't work
>> either. The text at the end of PDFBOX-2469 is somewhat unclear, but
>> it seems we didn't solve them all.
>
> I discussed the problem with Adreas already. See the comment
> https://issues.apache.org/jira/browse/PDFBOX-2469#comment-14216197
>
> In some documents the decryption is broken or something else does not
> seems working. So while decrypting and finalizing the stream, an
> exception will stop the decryption process.
>
> Ignoring the exception will help but let the document maybe in an
> incosistent form. Maybe we can use the "force" flag for the parser to
> skip this decryption errors. So people who work with the "force" flag
> will know what they do and can risk inconsistance.
The "old" parser is behaving wrong, see my comment in PDFBOX-2469 [1]. The 
exception is just a subsequent issue.

> +1 from my side :P because I need it only for signature parsing and
> verifying, which aren't encrypted at all.
>
> Best regards
> Thomas
>

BR
Andreas Lehmkühler

[1] 
https://issues.apache.org/jira/browse/PDFBOX-2469?focusedCommentId=14216027&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14216027

>>
>> Tilman
>>
>>
>>
>> Am 30.12.2014 um 03:15 schrieb Barry Zhao [Zhao]:
>>> Hi team,
>>>
>>> I see that the PDFBox has staged out new release 1.8.8, so I just
>>> try to use the new version.
>>> When I decrypt a PDF file which is decrypted, I got the exception
>>> bellow:
>>>
>>> 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 Testpdf10.main(Testpdf10.java:44)
>>> 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:1969) at
>>> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
>>> ... 9 more
>>>
>>> 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();
>>> }
>>> }
>>>
>>> I use the attachment file to do the operation.
>>>
>>>
>>> I found this
>>> http://stackoverflow.com/questions/26963718/badpaddingexception-when-decrypting-with-pdfbox
>>> in stackoverflow.
>>> I tried by the advices and it still not work.
>>> So I post this email to you. Hope to get your answer.
>>>
>>> Best wishes,
>>> Barry
>>
>


Re: PDFBOX-2469 still have problem while decrypting a pdf file

Posted by John Hewson <jo...@jahewson.com>.
The "force" flag has been removed in 2.0, so unless this is a 1.8-only issue then some other solution will be needed.

We're already very forgiving to broken PDFs, so it's fine to just log a warning and skip the offending content.

-- John

> On 30 Dec 2014, at 09:29, Thomas Chojecki <in...@rayman2200.de> wrote:
> 
> Am Tue, 30 Dec 2014  10:08:14 +0100
> schrieb Tilman Hausherr <TH...@t-online.de>:
> 
>> Hi,
> Hi Tilman,
> 
>> ...
>> 
>> And then there's the second one in PDFBOX-2469, that doesn't work 
>> either. The text at the end of PDFBOX-2469 is somewhat unclear, but
>> it seems we didn't solve them all.
> 
> I discussed the problem with Adreas already. See the comment 
> https://issues.apache.org/jira/browse/PDFBOX-2469#comment-14216197
> 
> In some documents the decryption is broken or something else does not
> seems working. So while decrypting and finalizing the stream, an
> exception will stop the decryption process.
> 
> Ignoring the exception will help but let the document maybe in an
> incosistent form. Maybe we can use the "force" flag for the parser to
> skip this decryption errors. So people who work with the "force" flag
> will know what they do and can risk inconsistance.
> 
> +1 from my side :P because I need it only for signature parsing and
> verifying, which aren't encrypted at all.
> 
> Best regards
> Thomas
> 
>> 
>> Tilman
>> 
>> 
>> 
>>> Am 30.12.2014 um 03:15 schrieb Barry Zhao [Zhao]:
>>> Hi team,
>>> 
>>> I see that the PDFBox has staged out new release 1.8.8, so I just
>>> try to use the new version.
>>> When I decrypt a PDF file which is decrypted, I got the exception
>>> bellow:
>>> 
>>> 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 Testpdf10.main(Testpdf10.java:44)
>>> 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:1969) at 
>>> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
>>> ... 9 more
>>> 
>>> 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();
>>> }
>>> }
>>> 
>>> I use the attachment file to do the operation.
>>> 
>>> 
>>> I found this 
>>> http://stackoverflow.com/questions/26963718/badpaddingexception-when-decrypting-with-pdfbox
>>> in stackoverflow.
>>> I tried by the advices and it still not work.
>>> So I post this email to you. Hope to get your answer.
>>> 
>>> Best wishes,
>>> Barry
> 

Re: PDFBOX-2469 still have problem while decrypting a pdf file

Posted by Thomas Chojecki <in...@rayman2200.de>.
Am Tue, 30 Dec 2014 10:08:14 +0100
schrieb Tilman Hausherr <TH...@t-online.de>:

> Hi,
Hi Tilman,

> ...
> 
> And then there's the second one in PDFBOX-2469, that doesn't work 
> either. The text at the end of PDFBOX-2469 is somewhat unclear, but
> it seems we didn't solve them all.

I discussed the problem with Adreas already. See the comment 
https://issues.apache.org/jira/browse/PDFBOX-2469#comment-14216197

In some documents the decryption is broken or something else does not
seems working. So while decrypting and finalizing the stream, an
exception will stop the decryption process.

Ignoring the exception will help but let the document maybe in an
incosistent form. Maybe we can use the "force" flag for the parser to
skip this decryption errors. So people who work with the "force" flag
will know what they do and can risk inconsistance.

+1 from my side :P because I need it only for signature parsing and
verifying, which aren't encrypted at all.

Best regards
Thomas

> 
> Tilman
> 
> 
> 
> Am 30.12.2014 um 03:15 schrieb Barry Zhao [Zhao]:
> > Hi team,
> >
> > I see that the PDFBox has staged out new release 1.8.8, so I just
> > try to use the new version.
> > When I decrypt a PDF file which is decrypted, I got the exception
> > bellow:
> >
> > 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 Testpdf10.main(Testpdf10.java:44)
> > 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:1969) at 
> > org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
> > ... 9 more
> >
> > 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();
> > }
> > }
> >
> > I use the attachment file to do the operation.
> >
> >
> > I found this 
> > http://stackoverflow.com/questions/26963718/badpaddingexception-when-decrypting-with-pdfbox
> > in stackoverflow.
> > I tried by the advices and it still not work.
> > So I post this email to you. Hope to get your answer.
> >
> > Best wishes,
> > Barry
> 


Re: PDFBOX-2469 still have problem while decrypting a pdf file

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,


Am 30.12.2014 um 10:08 schrieb Tilman Hausherr:
> Hi,
>
> Please try loadNonSeq(file,null).
>
> Nevertheless you are correct, it doesn't work with the "old" parser. What's even
> weirder is that there seem to be several of these i-9 forms. The first one from
> PDFBOX-2469 works, the one you attached (it landed in moderation) doesn't.
>
> And then there's the second one in PDFBOX-2469, that doesn't work either. The
> text at the end of PDFBOX-2469 is somewhat unclear, but it seems we didn't solve
> them all.
The fix in PDFBOX-2469 is  limited to the non-sequential parser and IMO the 
comments are clear about that.

> Tilman


BR
Andreas Lehmkühler
>
>
>
> Am 30.12.2014 um 03:15 schrieb Barry Zhao [Zhao]:
>> Hi team,
>>
>> I see that the PDFBox has staged out new release 1.8.8, so I just try to use
>> the new version.
>> When I decrypt a PDF file which is decrypted, I got the exception bellow:
>>
>> 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 Testpdf10.main(Testpdf10.java:44)
>> 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:1969)
>> at
>> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
>>
>> ... 9 more
>>
>> 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();
>> }
>> }
>>
>> I use the attachment file to do the operation.
>>
>>
>> I found this
>> http://stackoverflow.com/questions/26963718/badpaddingexception-when-decrypting-with-pdfbox
>> in stackoverflow.
>> I tried by the advices and it still not work.
>> So I post this email to you. Hope to get your answer.
>>
>> Best wishes,
>> Barry
>
>


Re: PDFBOX-2469 still have problem while decrypting a pdf file

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

Please try loadNonSeq(file,null).

Nevertheless you are correct, it doesn't work with the "old" parser. 
What's even weirder is that there seem to be several of these i-9 forms. 
The first one from PDFBOX-2469 works, the one you attached (it landed in 
moderation) doesn't.

And then there's the second one in PDFBOX-2469, that doesn't work 
either. The text at the end of PDFBOX-2469 is somewhat unclear, but it 
seems we didn't solve them all.

Tilman



Am 30.12.2014 um 03:15 schrieb Barry Zhao [Zhao]:
> Hi team,
>
> I see that the PDFBox has staged out new release 1.8.8, so I just try 
> to use the new version.
> When I decrypt a PDF file which is decrypted, I got the exception bellow:
>
> 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 Testpdf10.main(Testpdf10.java:44)
> 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:1969)
> at 
> org.apache.pdfbox.pdmodel.encryption.SecurityHandler.encryptData(SecurityHandler.java:351)
> ... 9 more
>
> 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();
> }
> }
>
> I use the attachment file to do the operation.
>
>
> I found this 
> http://stackoverflow.com/questions/26963718/badpaddingexception-when-decrypting-with-pdfbox in 
> stackoverflow.
> I tried by the advices and it still not work.
> So I post this email to you. Hope to get your answer.
>
> Best wishes,
> Barry