Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an encrypted ZIP file?

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] + ".zip" zip = zipfile.ZipFile (loczip, "w") zip.write (locfile) zip.close() 

But I couldn't find how to encrypt the files in the ZIP file. I could use system and call PKZIP -s, but I suppose there must be a more "Pythonic" way. I'm looking for an open source solution.

like image 289
PabloG Avatar asked Aug 20 '08 00:08

PabloG


People also ask

Can we Encrypt zip file?

Password protect a zip file (Windows 10 and macOS)Open WinZip and click Encrypt in the Actions pane. Enter a secure password when the dialog box appears. Click OK. Click the Options tab in the Actions pane and choose Encryption Settings.


1 Answers

I created a simple library to create a password encrypted zip file in python. - here

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

The library requires zlib.

I have checked that the file can be extracted in WINDOWS/MAC.

like image 147
Shin Aoyama Avatar answered Sep 29 '22 20:09

Shin Aoyama