I think you should do this as a BytesIO wrapper with transparent encryption during read/write operations, not an in-memory image encryptor.<p>And by "I think you should do" what I mean is "IO encryption already exists so you shouldn't need to do anything" (see <a href="https://developers.google.com/tink/encrypt-large-files-or-data-streams" rel="nofollow">https://developers.google.com/tink/encrypt-large-files-or-da...</a> for one example). But if you really like making things yourself, it would be very easy to just not use PIL and numpy and read blocks from a stream into a small R/W buffer.<p>1) Encryption has nothing to do with images. If you encrypt arbitrary data from the file system then you don't need PIL or numpy.<p>2) Right now if your decompressed image doesn't fit in RAM, then your code dies horribly.<p>Using the same system interfaces and same encryption without the reliance on numpy or PIL, you could accomplish the same feat but safer, faster, and more universally en/decrypting raw data from a chunked IO stream instead of treating images as special somehow. It will work against all files and will never overflow available resources. PIL can't even decode all image formats.<p>Leave the image decoding part to the code that actually does something with images.
Neat.
I've used nacl and its python bindings in the past, which were pretty easy to use for asymmetric scenarios [1].<p>Is there anything particularly special about this project?<p>[1] <a href="https://pynacl.readthedocs.io/en/latest/public/" rel="nofollow">https://pynacl.readthedocs.io/en/latest/public/</a>
Very cool. It would be neat if you had a MWE included so we could see an actual image get encrypted and decrypted in the README. I find sections like that, sometimes titled "Quick Start", the most instructive way to learn about the functionality of a new library at a glance.
Is there more context as to why something custom was desired here? Gpg, for example, can do symmetric AES256 as a "one liner". Not criticizing, just curious.