boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
733 stars 154 forks source link

PDF is Encrypted! Attempting to decrypt - not yet fully supported #196

Open pvin opened 3 years ago

pvin commented 3 years ago

@kevshin2 @boazsegev I'm using version (1.0.16) and tried (1.0.21) also, but still getting this error PDF is Encrypted! Attempting to decrypt - not yet fully supported.

I'm able to open the file in preview without password.

I see this issue, which is already discussed https://github.com/boazsegev/combine_pdf/issues/66 and closed but still getting, any help here?

technoir9 commented 3 years ago

@pvin @boazsegev I'm having the same issue (encrypted pdf file, but no password needed), a bit more details here:

File is encrypted - not supported.
/home/technoir/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/combine_pdf-1.0.21/lib/combine_pdf/decrypt.rb:187:in `raise_encrypted_error'
/home/technoir/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/combine_pdf-1.0.21/lib/combine_pdf/decrypt.rb:57:in `decrypt'
/home/technoir/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/combine_pdf-1.0.21/lib/combine_pdf/parser.rb:102:in `parse'
(...)
Data raising exception:
 {:P=>-1324
 :R=>4
 :StrF=>:StdCF
 :CF=>{:StdCF=>{:Type=>:CryptFilter
 :CFM=>:AESV2
 :Length=>16
 :EncryptMetadata=>false}}
 :Filter=>:Standard
 :Length=>128
 :U=>"<byte sequence>"
 :V=>4
 :StmF=>:StdCF
 :EncryptMetadata=>false
 :O=>"<byte sequence>"
 :indirect_generation_number=>0
 :indirect_reference_id=>170}

File metadata:

$ pdfinfo encrypted.pdf                                            
Title:          <redacted>
Creator:        Word
Producer:       Adobe Sign
CreationDate:   Thu Feb 11 15:05:43 2021 CET
ModDate:        Fri Mar 19 12:36:33 2021 CET
Tagged:         no
UserProperties: no
Suspects:       no
Form:           AcroForm
JavaScript:     no
Pages:          17
Encrypted:      yes (print:yes copy:yes change:no addNotes:no algorithm:AES)
Page size:      595 x 842 pts (A4)
Page rot:       0
File size:      311688 bytes
Optimized:      no
PDF version:    1.7

Removing this line seems to fix it for me: https://github.com/boazsegev/combine_pdf/blob/b7d281f074662595ea85d4fc626f9a932a674ceb/lib/combine_pdf/decrypt.rb#L57

reiz commented 2 years ago

@pvin I have the same issue.

@boazsegev what would it take to support encrypted files? I would be willing to pay a couple $ to resolve this issue. I'm using this Gem at ZEIT.IO. It's my bootstrapped business. Not super profitable yet, but it generates a bit of revenue. Having support of encrypted files would simplify my coding and increase customer happiness. I would pay 100 EUR to get this resolved. I know it's not much, but better than nothing ;-)

kalinchuk commented 1 year ago

I'm also willing to pay to get this resolved.

boazsegev commented 1 year ago

Hi @reiz and @kalinchuk ,

I don't think money is the issue... besides, depending on which country the payment is from, the money I'll have to pay the accountant to process the foreign payment would probably cost more than the €100 😅

Essentially there's already a stub class that should be called when encrypted files are recognized.

The two things that will have to be done is improve the recognition code and implement the decryption algorithms (which would have been easier if OpenSSL's API wasn't so terrible). Another optional feature needed would be support for a :password option in the Parser's options hash so that could be passed on to the decrypt implementation.