How do I hide a file inside an image with Python?

风流意气都作罢 提交于 2020-01-25 01:52:12

问题


I know it's possible in Batch using the 'copy' command with the '/B' switch, i.e.:

copy /B imagefile+hiddenfile newfile

My question is this; Is it possible to do this in Python, and if so, how?

This question is very similar, and it's answer is acceptable, but I am still curious;

Is there a way to do this without the stepic module?


回答1:


You don't need stepic for that.

>>> out = file("out.jpg", "wb")
>>> out.write(file("someimage.jpg", "rb").read())
>>> out.write(file("somehiddenfile.pdf", "rb").read())
>>> out.close()

stepic is something completely different it is for putting "really" hidden data into an image, whereas your copy approach (and also my snippet above) just appends the file after the image's data. It is quite easy to extract the "somehiddenfile.pdf" from the generated file, whereas extracting steganographic information out of a real image is a lot more difficult.




回答2:


stepic is a python package written to perform this operation - why not simply look at the source?



来源:https://stackoverflow.com/questions/17269923/how-do-i-hide-a-file-inside-an-image-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!