Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Encrypt Issue #88

Open
mpbunch opened this issue Aug 10, 2020 · 3 comments
Open

Potential Encrypt Issue #88

mpbunch opened this issue Aug 10, 2020 · 3 comments

Comments

@mpbunch
Copy link

mpbunch commented Aug 10, 2020

        [..., canvas, bytesio(), ...]
        
        can.save()
        new_pdf = PdfFileReader(packet)

        # Open template pdf
        existing_pdf = PdfFileReader(open(input_pdf_path, "rb"), strict=False)
        output = PdfFileWriter()
        # get first page of template
        page = existing_pdf.getPage(0)
        # merge first page of template with first page of canvas pdf
        page.mergePage(new_pdf.getPage(0))
        output.addPage(page)
        
        outputStream = open(self.output_pdf_path, "wb")
        # encrypt
        output.encrypt(user_pwd='', owner_pwd="password", use_128bit=True)
        # save
        output.write(outputStream)
        outputStream.close()

File generation works, file save works, file encryption doesn't.
I want to set an admin password that restricts pdf editing and copying of text, while freely allowing users to view the pdf.
When I open the pdf in acrobat pro, I am able to freely edit the pdf, even though acrobat says (SECURE) after the file name.

I'm not sure if this is an issue with my implementation, or within the library, but this does seem like a problem.

@pubpub-zz
Copy link

Hi,
I'm currently preparing a new version in a fork(https://github.com/pubpub-zz/PyPDF4). I made a tried as follow:
`

import pypdf
w=pypdf.PdfFileWriter(None,"E:/tst02.pdf")
w.write("e:/tst02a.pdf") #not crypted
w.encrypt("","tst")
w.write("e:/tst02a.pdf") #protected file
`
I opened it successfully with acrobat reader DC
Can you give me your feed back with my proposed version ?(not yet released but attached in here)

pypdf4-1.27.0PPzz_1-py2.py3-none-any.whl.zip

thanks,

@mpbunch
Copy link
Author

mpbunch commented Aug 18, 2020

@pubpub-zz The test outputted a pdf which could be opened in acrobat, but it was not secure, I could edit the file.
PyPDF should have similar functionality as reportlab. https://www.reportlab.com/docs/PdfEncryptIntro.pdf

image
image

@pubpub-zz
Copy link

@mpbunch ,
I understand : actually what you are looking for is a capability to define permissions when encrypting the file. I've upgraded the API:
encrypt(user_pwd, owner_pwd=None, use_128bit=True, permits=None,
can_print=True, can_modify=True, can_copy=True, can_annotate=True, can_fill=True, can_extract=True, can_assemble=True, print_fullquality=True)

I've also added 2 functions applicable to both readers and writers:
get_permissions():
return the encoded permissions as in integer (negative).
Returns:
• (int) – permissions as defined in document. If no permissions are defined, -1(all permitted) is returned
Raises:
• PdfReadError – if the document is encrypted and not yet decrypted.

decode_permissions():
return the encoded permissions as a human readable string
Returns:
• (string) – 0 substring of “can_print_high_res,can_print_low_res,can_modify,can_copy,can_annotate,can_fill,can_extract,can_assemble”
Raises:
• PdfReadError – if the document is encrypted and not yet decrypted.

Can you give me your feed back?
pypdf4-1.27.0PPzz_1-py2.py3-none-any.whl.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants