Stuk / jszip

Create, read and edit .zip files with Javascript
https://stuk.github.io/jszip/
Other
9.73k stars 1.3k forks source link

Working with encrypted archives using external libraries #285

Open HimeWorks opened 8 years ago

HimeWorks commented 8 years ago

There are JS libraries available for various encryption algorithms.

My understanding of how JSZip works is when I ask for a file to be loaded from the archive, it will automatically be decompressed for me.

I believe zip files are encrypted after they are compressed, so I will need to perform decryption before the decompression occurs.

Would it be possible to

  1. Provide an option to allow encrypted archives (simple flag), provided that
  2. We will be providing methods that will be executed BEFORE or AFTER the decompression occurs

So for example, I might set a beforeDecompress listener so that whenever async is called, it will grab the entry, run it through the callback, and then proceed to decompress it as usual.

My assumption is that the file directory can be read the same way as a zip archive without any encrypted entries.

dduponchel commented 8 years ago

You are correct, the content is compressed then encrypted. With a traditional PKWARE encryption, the header (needed to decrypt the file) is in the data section. With WinZip's AES encryption, the header is as an extra data of the entry. The metadata (local file headers, central directory) are only encrypted by PKWARE Strong Encryption but it's covered by a patent: we can ignore it.

JSZip uses internally a stream (async accumulates the result) but the idea is the same. This would need #248 (to get the header). In that case, we could "register" an object with a supports(zip entry) method and a transform(data) method. The same could be done with the compression.

See also #115.

xqdoo00o commented 4 years ago

I add some Aes decryption code, please see at #696. But I'm not sure if the code flow is right😂