您首先需要确定 zip 文件使用的加密类型。 WinZip 本身可能有一个报告工具会告诉您。我没有,所以不知道。
如果您可以访问任何命令行 zip 实用程序,您可以很容易地找到。
首先,如果您有unzip 的Infozip 实现可用,请使用-lv 选项运行它。如果您有一个非常新版本的unzip 可用并且它在方法列中显示AES_WG,则您的文件是AES 加密的。
$ unzip -lv my.zip
Archive: /home/paul/perl/ext/Gzip/IO-Zippo/scratch/sample-zip/7z/7z-win32-aes128.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
1933 AES_WG 884 54% 04-15-2010 22:26 00000000 0001-perl-74088.patch
-------- ------- --- -------
1933 884 54% 1 file
如果您的 unzip 较旧,则“方法”列中字符串 Unk:099 的存在意味着您的文件是 AES 加密的。
$ unzip -lv my.zip
Archive: IO-Zippo/scratch/sample-zip/7z/7z-win32-aes128.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
1933 Unk:099 884 54% 2010-04-15 22:26 00000000 0001-perl-74088.patch
-------- ------- --- -------
1933 884 54% 1 file
另一种选择是使用zipdetails(完全公开,我是 zipdetails 的作者)。寻找的关键是Compression Method 0063 'AES Encryption'这一行
$ zipdetails my.zip
0000 LOCAL HEADER #1 04034B50
0004 Extract Zip Spec 33 '5.1'
0005 Extract OS 00 'MS-DOS'
0006 General Purpose Flag 0001
[Bit 0] 1 'Encryption'
0008 Compression Method 0063 'AES Encryption'
...
如果事实证明您确实有 AES 加密,并且您需要一种 python 方式来读取文件,那么标准的zipfile 方法将不起作用。目前zipfile 仅支持弱加密。
有关读取 AES 加密 Zip 文件的其他 python 方法,请参阅Python unzip AES-128 encrypted file