Python unzip AES-128 encrypted file

笑着哭i 提交于 2019-12-01 20:31:10

The zipfile module from the Python standard library supports only CRC32 encrypted zip files (see here: http://hg.python.org/cpython/file/71adf21421d9/Lib/zipfile.py#l420 ). So, there is no way around some 3rd party dependency.

The easiest way would be to just install 7zip and call the commandline utility 7z using the subprocess module from the standard lib:

import subprocess
subprocess.call(["7z", "x", "-ppassword", "test.zip"])

Another option would be the python module "PyLzma" which can also handle AES encrypted 7zip archives: https://github.com/fancycode/pylzma . It doesn't directly support decrypting classic zip files but you could use its routines to write your own decompressor function.

You can use the library pyzipper: https://github.com/danifus/pyzipper. It works nearly the same as Python's zipfile:

import pyzipper

with pyzipper.AESZipFile('my_archive.zip') as f:
    f.pwd = b'myPassword'
    print(f.infolist())
    file_content = f.read('testfile.txt')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!