如何在应用程序引擎 blobstore 上加密 zip 文件

发布于 2024-12-05 06:51:52 字数 908 浏览 1 评论 0原文

我有一个问题,如何加密 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2024-12-12 06:51:52

首先,请允许我说 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文