TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Simple Image encrypt/decrypt using Python

30 pointsby pavlovskyialmost 4 years ago

6 comments

BugsJustFindMealmost 4 years ago
I think you should do this as a BytesIO wrapper with transparent encryption during read&#x2F;write operations, not an in-memory image encryptor.<p>And by &quot;I think you should do&quot; what I mean is &quot;IO encryption already exists so you shouldn&#x27;t need to do anything&quot; (see <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;tink&#x2F;encrypt-large-files-or-data-streams" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;tink&#x2F;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&#x2F;W buffer.<p>1) Encryption has nothing to do with images. If you encrypt arbitrary data from the file system then you don&#x27;t need PIL or numpy.<p>2) Right now if your decompressed image doesn&#x27;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&#x2F;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&#x27;t even decode all image formats.<p>Leave the image decoding part to the code that actually does something with images.
评论 #28221825 未加载
uniqueuidalmost 4 years ago
Neat. I&#x27;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:&#x2F;&#x2F;pynacl.readthedocs.io&#x2F;en&#x2F;latest&#x2F;public&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pynacl.readthedocs.io&#x2F;en&#x2F;latest&#x2F;public&#x2F;</a>
评论 #28220361 未加载
ryan-duvealmost 4 years ago
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 &quot;Quick Start&quot;, the most instructive way to learn about the functionality of a new library at a glance.
评论 #28219923 未加载
metalliqazalmost 4 years ago
Is there a use case that would make this preferable to storing images (and other data) on an encrypted disk?
评论 #28234039 未加载
评论 #28220966 未加载
tyingqalmost 4 years ago
Is there more context as to why something custom was desired here? Gpg, for example, can do symmetric AES256 as a &quot;one liner&quot;. Not criticizing, just curious.
评论 #28220951 未加载
28194608almost 4 years ago
It would be great if the secret_key goes through a time consuming hashing algorithm like bcrypt.
评论 #28221352 未加载