Python: write file directly to encrypted/password-protected archive file

Viewed 24

I want to save data from memory directly into some encrypted file archive format (such as zip, 7z, tar, rar...) that can be later opened by 7zip, such that:

  1. the data is at no point written in an unencrypted format onto disk (by storing temporary files to disk and then using a process to pack them for example)

  2. such that the archive can later be extracted into decrypted files using 7zip (which supports a wide array of popular archive file formats) and

  3. So that files can be added one by one without the adding taking more and more time as the archive grows.

Filenames may be clear-text and the file data does only have to be protected from reading, not from replacing or other kind of tampering (so regular zip password protection for example would be enough).

I tried to use the ZipFile library, but after quite some tinkering I found out that it supports passwords only for decryption, not encryption.

I also looked at py7zr, but that only supports adding files from disk and not directly from bytearray.

What library and archive format can I use in Python to achieve this?

0 Answers
Related