![]() ![]() ![]() ![]() The ZIP file password protection feature is available on Windows XP, unlike Windows Vista or Windows 7 which do not include the feature. Method #1: To Create Password Protected ZIP file in Windows XP Method 3: Password Protect Your ZIP File with WINRAR.Method 2: Make A Password Protected ZIP File with 7-Zip Utility.Method 1: To Create Password Protected ZIP file in Windows XP.Z.extract(testfile, pwd=zipPass) #Extract first file Testfile = filesInArray #First archive in list ZipPass = bytes(zipPass, encoding='utf-8') #Str to BytesįilesInArray = z.namelist() #Get all files Z = zipfile.ZipFile(fileName, 'a') #Set zipfile object If it works, remove the extracted file, and if it doesn't, no harm done. I did first retry the z.testzip() and it does actually catch the bad passwords, but after seeing that it wasn't reliable (apparently hash collisions that allow for bad passwords to somehow match a small hash), I decided to use the password, extract the first file it sees in the archive, and then extract it. See here for example of how to use pexpect to accomplish this: Use subprocess to send a password_Īfter all of the lovely replies, I did find a workaround for this just in case someone needs the answer! I think something like pexpect might be a solution for this, but I haven't spent the time to make that work. You cannot simply write zipPass into the stdin of the n with input=. I looked into fixing the whole "exposed password" issue with -P. #WARNING the linux manual page for 'zip' states -P is UNSECURE. #TODO: handle filename existing in zipFilename #TODO: handle zipfile not-exist and existing may have to pass # Note this is a linux only solution, os dependency will need to be checked #Next to add file with password cannot use zipfile because password not supported #TODO: compare contents of known.txt with actual With zFile.open('known.txt') as knownFile: With zipfile.ZipFile(zipFilename, 'r') as zFile: #If there is a file that we know the plain-text (or original binary) handling when the zipfile already exists AND when it doesn't.Handling when a file exists already in the zip file.Comparing file contents to validate password.Something that you could do is utilize subprocess to add files with a password.įurther, if you wanted to "validate" the entered password first, you could do something like this but you'd have to know the contents of the file because decrypt will happily decrypt any file with any password, the plaintext result will just be not correct. It supports decryption of encrypted files in ZIP archives, but it currently cannot create an encrypted file.ĮDIT: Further, looking into python bugs Issue 34546: Add encryption support to zipfile it appears that in order to not perpetuate a weak password scheme that is used in zip, they opted to not include it. So you won't be able to add files with a password. What I found in the documentation for zipfile is that the library supports decryption only with a password. I was expecting to get BadPasswordForFile. TL DR: z.write() doesn't throw an exception and neither does z.setpassword() or anything zipfile related when fed the incorrect password, and willingly adds files no matter what. I am not sure what I am missing here, but I was looking around for anything in zipfile that can handle encrypted zipfiles and add files into them using the password, as the only thing I have is the ``z.setpassword()` function that seems to not work here. ZipPass = bytes(zipPass, encoding='utf-8') ZipPass = str(input("Please enter the zip password: ")) Z = zipfile.ZipFile('test.zip', 'a') #Set zipfile object I posted the minimalist code below: import zipfile I checked for any ignored exceptions or anything, but nothing seems to be fairly obvious. I have an encrypted ZIP file and for some reason, any password I feed it doesn't seem to matter as it can add files to the archive regardless. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |