The duplicate question: https://stackoverflow.com/a/2366917/874188Code to create a password encrypted zip file? has an answer that recommends using 7z
instead of zip
. My experience bears this out.
Copy/pasting the answer by @JFSebastian@jfs here too, for completeness:
To create encrypted zip archive (named 'myarchive.zip'
) using open-source 7-Zip
utility:
rc = subprocess.call(['7z', 'a', '-mem=AES256', '-pP4$$W0rd', '-y', 'myarchive.zip'] +
['first_file.txt', 'second.file'])
To install 7-Zip, type:
$ sudo apt-get install p7zip-full
To unzip by hand (to demonstrate compatibility with zip utility), type:
$ unzip myarchive.zip
And enter P4$$W0rd
at the prompt.
Or the same in Python 2.6+:
>>> zipfile.ZipFile('myarchive.zip').extractall(pwd='P4$$W0rd')