There are many excellent libraries to open zip files on the client as: zip.js, jszip etc ... But I could not find any library that can open an encrypted zip file. is there a solution to open a zip file on the client side (in the browser)?
Asked
Active
Viewed 2,921 times
5
-
did you got any solution for this ? It will be great if u share that. – Achu Dec 22 '16 at 10:39
1 Answers
3
Zip.js supports encryption. Try it on the demo:
https://gildas-lormeau.github.io/zip.js/demos/demo-read-file.html. Here is below an example of how to check the password of a zip file (provided as a Blob
object) is valid or not.
const verifyZipPassword = async (file, password) => {
let reader;
try {
reader = new zip.ZipReader(new zip.BlobReader(file), { password });
const entries = await reader.getEntries();
for (const entry of entries) {
try {
await entry.getData(new zip.BlobWriter());
} catch (error) {
if (error.message === zip.ERR_ENCRYPTED ||
error.message === zip.ERR_INVALID_PASSWORD) {
return false;
} else {
throw error;
}
}
}
} finally {
await reader.close();
}
return true;
};

Bao To Quoc
- 344
- 1
- 6