tags:

views:

1197

answers:

3

I'm 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.

+2  A: 

You'll need the Chilkat library. It's commercial, but has a free evaluation and seems pretty nice.

Here's an example I got from here:

import chilkat

# Demonstrates how to create a WinZip-compatible 128-bit AES strong encrypted zip
zip = chilkat.CkZip()
zip.UnlockComponent("anything for 30-day trial")

zip.NewZip("strongEncrypted.zip")

# Set the Encryption property = 4, which indicates WinZip compatible AES encryption.
zip.put_Encryption(4)
# The key length can be 128, 192, or 256.
zip.put_EncryptKeyLength(128)
zip.SetPassword("secret")

zip.AppendFiles("exampleData/*",True)
zip.WriteZip()
Harley
+2  A: 

@Harley:

I already saw the Chilkat examples, but I'm looking for an open source option (sorry didn't mention this in my original post)

I keep looking in google, but without luck.

PabloG
A: 

you can use ncrypt.

Shikhar Mall