Python解压缩AES-128加密文件 [英] Python unzip AES-128 encrypted file

查看:650
本文介绍了Python解压缩AES-128加密文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于ZipFile会引发Bad Password错误,因此是否可以使用python直接解压缩AES-128加密文件。如果我使用7zip可以正常工作,那么密码是正确的,但是再次需要将7zip安装为依赖项。

Is there a way to decompress an AES-128 encrypte file directly with python, since ZipFile throws a Bad Password error. If i use 7zip it works, so the password is correct, but then again 7zip needs to be installed as a dependency.

我尝试过的事情:

from ZipFile import ZipFile
zip = ZipFile('test.zip')
zip.extractall(pwd='password')

这将引发Bad Password异常。

This throws the Bad Password exception.

使用7zip检查文件

7z l -slt test.zip

这将返回:

Encrypted = +
Method = pkAES-128 Deflate


推荐答案

Python标准库仅支持CRC32加密的zip文件(请参见此处: http: //hg.python.org/cpython/file/71adf21421d9/Lib/zipfile.py#l420 )。因此,无法避免某些第三方依赖。

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.

最简单的方法是安装7zip并使用 7z >标准子库中的>子过程模块:

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"])

另一个选项将是python模块 PyLzma,该模块也可以处理AES加密的7zip存档: https://github.com/fancycode / pylzma 。它不直接支持解密经典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.

这篇关于Python解压缩AES-128加密文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆