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)?
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;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With