Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3889

javax.crypto.BadPaddingException: Given final block not properly padded

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.13
    • Fix Version/s: 1.8.14
    • Component/s: Crypto, Documentation
    • Labels:
    • Environment:
      Java 1.8. Pdfbox 1.8.13 Windows and Linux
    • Flags:
      Important

      Description

      Using the attached pdf, When running the pdf through org.apache.pdfbox.pdmodel.encryption.SecurityHandler I get
      BadPaddingException.

      The exception occurs when it is processing
      nextObj = COSObject

      {3304,0}

      I see: nextCOSBase = COSDictionary{(COSName

      {Length}

      :COSInt

      {3504}

      ) (COSName

      {Subtype}

      :COSName

      {XML}

      ) (COSName

      {Type}

      :COSName

      {Metadata}

      ) }

      The problem is that SecurityHandler.proceedDecryption() runs decryptObject(nextObj);
      and then decrypt(base, objNum, genNum) and then decryptStream()

      However for this object decryptStream doesn't actually decrypt anything because the type is xml.

      So when decryptStream calls encryptData() encryptData() throws the bad packet exception.
      output.write(decryptCipher.doFinal()); throws the exception because the data buffer is all zeros. It has nothing in it. I recommend that encryption be skipped if the data buffer has all zeros.

        Attachments

        1. 14-03-1159.pdf
          392 kB
          Lucille Wilson

          Activity

            People

            • Assignee:
              tilman Tilman Hausherr
              Reporter:
              lucille.wilson Lucille Wilson
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified