如何在应用程序引擎 blobstore 上加密 zip 文件
我有一个问题,如何加密 zip 类型的压缩 blob。由于某些原因我无法使用 chilkat 模块,zipfile 模块仅提供解密,所以我不知道使用什么来用密钥加密 zip。
您能给我一些如何解决这个问题的建议吗?
理想的解决方案看起来像这样:
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_filename = file.namelist()[0].split('.')[0] + '.zip')
with files.open(outputStream, 'a') as f:
f.write(output.getvalue())
files.finalize(outputStream)
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_filename = file.namelist()[0].split('.')[0] + '.zip')
with files.open(outputStream, 'a') as f:
f.write(output.getvalue())
files.finalize(outputStream)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请允许我说 zip 加密很弱而且已经过时了。如果您需要强大的安全性,则不应依赖它。这已在许多论文中得到证明(Google 表示最流行的是 Eli Biham 和 Paul C. Kocher 撰写的“Known Plaintext Attack on the PKZIP Stream Cipher”)。
其次,GAE 仅适用于纯 Python 的库。您可能无法使用 chilkat,因为它是一个 C 库。
第三,纯Python中的zip文件加密/解密会非常慢,并且可能你会遇到GAE的CPU问题......
也许你应该寻找另一种方法来做到这一点?
问候
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