调用zipfile对传统加密的zip文件进行解压可以成功,但是当zip为非传统加密方式时无法解压,求解答,谢谢~

当压缩成zip文件,勾选上“传统加密”时,可以通过下面代码进行解压。

当不勾选”传统加密”时,无法解压,并报如下错误:

import zipfile
zip_file = zipfile.ZipFile(r'C:\New\test.zip')  # 文件的路径与文件名
zip_list = zip_file.namelist()  # 得到压缩包里所有文件

for f in zip_list:
    zip_file.extract(f, r'C:\New', pwd="123".encode("utf-8"))  # 循环解压文件到指定目录

zip_file.close()  # 关闭文件,必须有,释放内存
Jason990420
最佳答案

ZIP legacy encryption

By default, WinRAR uses AES-256 in CTR mode to encrypt ZIP archives. While AES-256 is significantly more secure than ZIP 2.0 legacy encryption algorithm, it can be incompatible with some older unzip software. If compatibility with such tools is required, you can enable "ZIP legacy encryption" option in the password dialog or use -mezl switch in the command line mode.

The zipfile module from the Python standard library supports only CRC32 encrypted zip files.

Try pyzipper, A 100% API compatible replacement for Python's zipfile that can read and write AES encrypted zip files.

1周前 评论
CoderandMan (楼主) 1周前
讨论数量: 1
Jason990420

ZIP legacy encryption

By default, WinRAR uses AES-256 in CTR mode to encrypt ZIP archives. While AES-256 is significantly more secure than ZIP 2.0 legacy encryption algorithm, it can be incompatible with some older unzip software. If compatibility with such tools is required, you can enable "ZIP legacy encryption" option in the password dialog or use -mezl switch in the command line mode.

The zipfile module from the Python standard library supports only CRC32 encrypted zip files.

Try pyzipper, A 100% API compatible replacement for Python's zipfile that can read and write AES encrypted zip files.

1周前 评论
CoderandMan (楼主) 1周前

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!