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

Zip with password is not working #34

Open
hai-nguyen-trung opened this issue Jul 12, 2021 · 3 comments
Open

Zip with password is not working #34

hai-nguyen-trung opened this issue Jul 12, 2021 · 3 comments

Comments

@hai-nguyen-trung
Copy link

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

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.

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