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 2015/01/09 09:55:36 UTC
Problem while decrypting a pdf file in Linux
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
Re: Problem while decrypting a pdf file in Linux
Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,
could you try using PDFBox 1.8.8 as this should have been addressed there [https://issues.apache.org/jira/browse/PDFBOX-2522]
BR
Maruan Sahyoun
Am 09.01.2015 um 09:55 schrieb Barry Zhao [Zhao] <zh...@tibco-support.com>:
> 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
Re: Problem while decrypting a pdf file in Linux
Posted by "Barry Zhao [Zhao]" <zh...@tibco-support.com>.
On Fri, Jan 9, 2015 at 5:59 PM, Barry Zhao [Zhao] <zhazhao@tibco-support.com
> wrote:
> 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
>>
>
>
Re: Problem while decrypting a pdf file in Linux
Posted by "Barry Zhao [Zhao]" <zh...@tibco-support.com>.
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
>
Re: Problem while decrypting a pdf file in Linux
Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,
Please try PDDocument.loadNonSeq instead of load. It should then work
with 1.8.8.
If it still doesn't work, please open an issue in JIRA, but read this to
create a good bug report:
https://pdfbox.apache.org/support.html
Tilman
Am 09.01.2015 um 09:55 schrieb Barry Zhao [Zhao]:
> 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