How to encrypt zip file on app engine blobstore
I have a problem how to encrypt compressed blobs of type zip. Because of some reasons I cannot use chilkat module, zipfile module provides only decryption, so I do not know what to use to encrypt zips with a key.
Could you please give me some suggestions how this problem is (could be) solved?
ideal solution would look something like this:
blob_info = blobstore.BlobInfo.all()[0] #lets say we want to read the first blob we find
blob_reader = blobstore.BlobReader(blob_info.key())
file = zipfile.ZipFile(blob_reader, 'r')
data = file.read(file.namelist()[0])
output = StringIO.StringIO()
outfile = zipfile.ZipFile(output, "w")
outfile.writestr(file.namelist()[0], data)
outfile.setpassword('testpass') #it would be nice if there was a module that could set pass like this, .setpassword() only works with decryption
outfile.close()
outputStream = files.blobstore.create(mime_type='application/zip', _blobinfo_uploaded开发者_如何学C_filename = file.namelist()[0].split('.')[0] + '.zip')
with files.open(outputStream, 'a') as f:
f.write(output.getvalue())
files.finalize(outputStream)
First of all, allow me to say that zip encryption is weak and obsolete. You shouldn't rely on it if you need a strong security. This has been proved on many papers (Google says that the most popular is "Known Plaintext Attack on the PKZIP Stream Cipher" by Eli Biham and Paul C. Kocher).
Second, GAE only works with libraries that are pure python. Probably you can't use chilkat because it is a C library.
Third, zip file encryption/decryption in pure python is going to be slow as hell, and probably you'll have CPU problems with GAE...
Perhaps you should look into another way to do this?
Regards
精彩评论