Friday, 18 March 2022

Write in-memory data to an encrypted ZIP or 7Z (without using an on-disk temp file)

I have 2 GB of data in memory (for example data = b'ab' * 1000000000) that I would like to write in a encrypted ZIP or 7Z file.

How to do this without writing data to a temporary on-disk file?

Is it possible with only Python built-in tools (+ optionally 7z)?

I've already looked at this:

  • ZipFile.writestr writes from a in-memory string/bytes which is good but:

  • ZipFile.setpassword: only for read, and not write

  • How to create an encrypted ZIP file? : most answers use a file as input (and cannot work with in-memory data), especially the solutions with pyminizip and those with:

    subprocess.call(['7z', 'a', '-mem=AES256', '-pP4$$W0rd', '-y', 'myarchive.zip']... 
    

    Other solutions require to trust an implementation of cryptography by a third-party tool (see comments), so I would like to avoid them.



from Write in-memory data to an encrypted ZIP or 7Z (without using an on-disk temp file)

No comments:

Post a Comment