如何使用 Python 在图像中隐藏文件?

mic*_*ers 3 python security steganography image file

我知道可以在 Batch 中使用带有 '/B' 开关的 'copy' 命令,即:

copy /B imagefile+hiddenfile newfile
Run Code Online (Sandbox Code Playgroud)

我的问题是这样的;是否可以在 Python 中执行此操作,如果可以,如何执行?

这个问题很相似,答案是可以接受的,但我还是很好奇;

有没有办法在没有 stepic 模块的情况下做到这一点?

maw*_*awi 5

你不需要步骤。

>>> out = file("out.jpg", "wb")
>>> out.write(file("someimage.jpg", "rb").read())
>>> out.write(file("somehiddenfile.pdf", "rb").read())
>>> out.close()
Run Code Online (Sandbox Code Playgroud)

stepic 是完全不同的东西,它用于将“真正”隐藏的数据放入图像中,而您的copy方法(以及我上面的代码段)只是在图像数据之后附加文件。从生成的文件中提取“somehiddenfile.pdf”非常容易,而从真实图像中提取隐写信息要困难得多。