Skip to content

Instantly share code, notes, and snippets.

@colmcoughlan
Last active May 2, 2022 10:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save colmcoughlan/db1384156b8efe6676c9a6cc47756933 to your computer and use it in GitHub Desktop.
Save colmcoughlan/db1384156b8efe6676c9a6cc47756933 to your computer and use it in GitHub Desktop.
Extract an encrypted zip file with a password using Python 3

Extract files from an encrpyted zip file with python3

Take care, python3's zipfile only supports encrypted zip files that use CRC-32 based encryption This seems to be the default for the "zip" program on linux, but this doesn't work for AES encryption, or for many Windows based zip solutions See https://github.com/python/cpython/blob/3.6/Lib/zipfile.py for more details

from zipfile import ZipFile

zip_file = 'test.zip'
password = 'password'

with ZipFile(zip_file) as zf:
  zf.extractall(pwd=bytes(password,'utf-8'))
@secraven
Copy link

The variable zip_file is missing an equal sign vs. a dash.

@colmcoughlan
Copy link
Author

Thanks @secraven - I don't know how that even happened!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment