Skip to content

Instantly share code, notes, and snippets.

@colmcoughlan
Last active December 2, 2025 22:26
Show Gist options
  • Select an option

  • Save colmcoughlan/db1384156b8efe6676c9a6cc47756933 to your computer and use it in GitHub Desktop.

Select an option

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!

@sergeevabc
Copy link

sergeevabc commented Dec 2, 2025

Is it possible to unpack password-protected ZIP archive via Python using a command-line one-liner?
With non-encrypted archives it is relatively straight-forward: python -m zipfile -e in.zip .

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