Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

Handle encyrpted pdf of other than "algorithm 1 or 2" #19

Description

@OzzieIsaacs

I'm using version 1.06 of pyPDF3.
Currently pyPDF3 is only capable of handling "algorithm 1 and 2 encrypted pdfs". I would love to have also the other algorithms decodes. For my use case decrypting the document info header would be sufficient.

An encrypted file can be downloaded from here:
https://cloud.3dissue.net/24308/24333/24567/65779/Position_4.21-211104-DE-web-20211203082446.pdf

The following code sample demonstrates the problem (having the above mentioned pdf downloaded and renamed to encrypt.pdf):

from PyPDF3 import PdfFileReader
with open('encrypt.pdf', 'rb') as f:
    pdf_file = PdfFileReader(f)
    doc_info = pdf_file.getDocumentInfo()

This code throws the error:
PyPDF3.utils.PdfReadError: file has not been decrypted

Adding an additional decrypt statement like this:

from PyPDF3 import PdfFileReader
with open('encrypt.pdf', 'rb') as f:
    pdf_file = PdfFileReader(f)
    if pdf_file.isEncrypted:
        pdf_file.decrypt('')
    doc_info = pdf_file.getDocumentInfo()

leads to:
NotImplementedError: only algorithm code 1 and 2 are supported. This PDF uses code 5

For your reference the content of the relevant variables in this case:
decrypt_failed


I found "qpdf" which is able to handle the encryption of this files. The decryption algorithm of qpdf can be found in file https://raw.githubusercontent.com/qpdf/qpdf/main/libqpdf/QPDF_encryption.cc

Would be great if somebody could catch up from here and implement the decryption in pypdf3.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions