galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.15k stars 170 forks source link

Encryption works for Adobe, not in Mac Preview #226

Open simonaberry opened 6 years ago

simonaberry commented 6 years ago

I have encrypted a file as follows

   {
      userPassword: '',
      ownerPassword: 'XXX',
      userProtectionFlag: 4,
      version: hummus.ePDFVersion16
    }

If I view the permissions Adobe I see

image

However, if I inspect the exact same file in Mac's Preview application

preview

And Preview is allowing me to happily copy any text ....

Does Mac use a different pdf security specification ??

simonaberry commented 6 years ago

From https://www.pdflib.com/knowledge-base/pdf-password-security/encryption/

Note that AES-256 is not supported by the native PDF viewers on OS X/macOS (tested up to OS X 10.10.3) and iOS (tested up to iOS 8.1.3)

simonaberry commented 6 years ago

:-( Tried ePDFVersion15 & ePDFVersion14, but macOs is still not respecting the permissions

chunyenHuang commented 6 years ago

How about you try

{
     userPassword: '',
     password: 'XXX',
     ownerPassword: 'XXX',
     userProtectionFlag: 4
}
screen shot 2017-12-03 at 12 15 10 am

This is output of my test pdf from https://github.com/chunyenHuang/hummusRecipe/blob/master/lib/encrypt.js#L14

simonaberry commented 6 years ago

unfortunately no - Mac Preview is still not respecting the encryption..... ;-(

mhio commented 4 years ago

Works for me on 10.14 and hummus@1.0.108

It did not work initially for me due to not specifying the blank user password userPassword: '' like this:

     {
      version: hummus.ePDFVersion17,
      ownerPassword: config.contract_pdf_password,
      userProtectionFlag: 4,
    }

When I added that in, it was fine:

    const pdf_writer = hummus.createWriter(output_file, {
      version: hummus.ePDFVersion17,
      userPassword: '',
      ownerPassword: config.contract_pdf_password,
      userProtectionFlag: 4,
    })