pyfilesystem2 icon indicating copy to clipboard operation
pyfilesystem2 copied to clipboard

Way to open password protected zip file

Open tzing opened this issue 6 years ago • 2 comments

As python built-in zipfile provides setpassowrd for opening the password protected zip file, is it proper to add a interface to set password on ReadZipFS and even ZipFS?

I known there is a workaround is to access the private member

zipf._zip.setpassword( ... )

but i still want a more convenience way

Yet another problem is-- setpassword is only valid for extract file but not for compression. Just wonder if it would be the concern on creating this sort of interface.

tzing avatar Dec 03 '19 02:12 tzing

Yeah, probably makes sense to add a pwd=None parameter to the ZipFs constructor, and then raise an error if write == True and pwd is not None ?

Looking at Python's zipfile docs, it seems there's a 'default password' for the zipfile (set with setpassword) and also the option to have different passwords for each file within the zip https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.read I didn't even know that per-file passwords were something that zip files allowed :wink:

I guess ZipFs could support the default passsword, but there's probably no way for it to support per-file passwords.

lurch avatar Dec 03 '19 17:12 lurch

Yeah, probably makes sense to add a pwd=None parameter to the ZipFs constructor, and then raise an error if write == True and pwd is not None ?

👍

I guess ZipFs could support the default password, but there's probably no way for it to support per-file passwords.

It would be possible to implement per-file passwords with the options keyword arguments on open and other methods.

I don't know if anything has changed regarding passwords in zip, but my understanding was that the password protection was very weak and vulnerable to brute force cracking. Not opposed to adding zip password support though, if it is useful to someone.

willmcgugan avatar Dec 03 '19 17:12 willmcgugan