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

[BUG] Protected files cannot be signed #169

Closed
knadh opened this issue Sep 14, 2019 · 7 comments
Closed

[BUG] Protected files cannot be signed #169

knadh opened this issue Sep 14, 2019 · 7 comments
Labels
bug Something isn't working signatures digital signatures

Comments

@knadh
Copy link

knadh commented Sep 14, 2019

Description

A PDF that's already password protected, or one that's created with unipdf's Encrypt() can no longer be digitally signed using the Appender{}. It throws the error page 1 not found.

Expected Behavior

It should be possible to open a PDF, decrypt it using Decrypt(), and use an Appender{} to apply a digital signature.

NewPdfAppender() makes a copy of an incoming reader

a.roReader, err = NewPdfReader(a.rs)
. It seems though that at this point, the decryption is lost. I hardcoded a .Decrypt() right after the copy is made and the error vanished, but the output lost all PDF contents and produced a blank page. This could potentially be due to the object comparison that happens in the update methods in the Appender.

@gunnsth
Copy link
Contributor

gunnsth commented Oct 5, 2019

@adrg Did #175 fix this issue also?

@adrg
Copy link
Collaborator

adrg commented Oct 8, 2019

@gunnsth No, #175 solves a different issue.
@knadh Thank you for reporting the issue. We are trying to come up with a solution to treat this case.

In the meantime, as a workaround, you could use a writer to create a temporary file with no encryption and use that with the appender. What I'm suggesting is basically:

- Create reader from original file
- Decrypt
- Transfer everything to a new writer
- Save to a temporary file or to a memory buffer.
- Create a new reader from the previously saved file.
- Feed that to the appender.

@gunnsth
Copy link
Contributor

gunnsth commented Jun 2, 2020

@knadh Were you able to try the workaround suggested?

@gunnsth gunnsth added bug Something isn't working signatures digital signatures labels Jun 2, 2020
@knadh
Copy link
Author

knadh commented Jun 3, 2020

My memory is a little hazy here, but I think you would end up decrypting a password protected file and signing it, but losing password protection in the process. As in, it didn't work.

@galihrivanto
Copy link

Hi, is there any update?

I am facing same issue and workaround doesn't work. As mentioned by @knadh using workaround will losing password protection in signed file

@gunnsth
Copy link
Contributor

gunnsth commented Sep 24, 2021

Fixed in https://github.com/unidoc/unipdf/releases/tag/v3.29.0
See also new example https://github.com/unidoc/unipdf-examples/blob/master/signatures/pdf_sign_and_encrypt_pdf.go

@gunnsth gunnsth closed this as completed Sep 24, 2021
@galihrivanto
Copy link

it works perfectly for me. thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working signatures digital signatures
Projects
None yet
Development

No branches or pull requests

4 participants