Create an encrypted ZIP file in Python

后端 未结 5 784
一向
一向 2020-11-28 07:02

I am creating an ZIP file with ZipFile in Python 2.5, it works ok so far:

import zipfile, os

locfile = \"test.txt\"
loczip = os.path.splitext (locfile)[0] +         


        
5条回答
  •  清酒与你
    2020-11-28 07:35

    pyminizip works great in creating a password protected zip file. For unziping ,it fails at some situations. Tested on python 3.7.3

    Here, i used pyminizip for encrypting the file.

    import pyminizip
    compression_level = 5 # 1-9
    pyminizip.compress("src.txt",'src', "dst.zip", "password", compression_level)
    

    For unzip, I used zip file module:

    from zipfile import ZipFile
    
    with ZipFile('/home/paulsteven/dst.zip') as zf:
        zf.extractall(pwd=b'password')
    

提交回复
热议问题