ksoichiro / node-archiver-zip-encryptable

An extension for archiver to zip with password encryption.
MIT License
12 stars 1 forks source link

Zip with password is not working #34

Open hai-nguyen-trung opened 3 years ago

hai-nguyen-trung commented 3 years ago

I tried to use the example to zip files with the password test but can unzip without any password input. Please help to check. Thanks.

hai-nguyen-trung commented 3 years ago

Sorry, it because I zip encrypted with an empty text file. If the file has value then it's working fine. But it's expecting it will require the password even if it's an empty file, isn't it?

ksoichiro commented 3 years ago

But it's expecting it will require the password even if it's an empty file, isn't it?

Maybe it depends on how you unzip the file (in other words, it depends on the unzip application), I think. 🤔

How did you unzip the file? I checked that on macOS and unzip asked me to input password even if the file inside the zip file is empty.

Here is my procedure:

  1. Create encrypted zip with empty text file:
var fs = require('fs');
var archiver = require('archiver');
archiver.registerFormat('zip-encryptable', require('archiver-zip-encryptable'));
var output = fs.createWriteStream(__dirname + '/example.zip');
var archive = archiver('zip-encryptable', {
  zlib: { level: 9 },
  forceLocalTime: true,
  password: 'test'
});
archive.pipe(output);
archive.append(Buffer.from(''), { name: 'test.txt' });
archive.finalize();
❯ node index.js
  1. Confirm that test.txt is empty:
❯ zipinfo example.zip
Archive:  example.zip
Zip file size: 142 bytes, number of entries: 1
-rw-r--r--  4.5 unx        0 Bl stor 21-Jul-13 23:42 test.txt
1 file, 0 bytes uncompressed, 0 bytes compressed:  0.0%
  1. Try to unzip the file with incorrect password:
❯ unzip example.zip
Archive:  example.zip
[example.zip] test.txt password:
password incorrect--reenter:
password incorrect--reenter:
   skipping: test.txt                incorrect password
ksoichiro commented 3 years ago

FYI. Even if the target file is empty, there is data named "encryption header" in the encrypted zip file and applications to unzip should be able to validate password with that.

Please see "6.1 Traditional PKWARE Decryption" section in https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT for details.