我有289个字节的数据要嵌入jpg文件。当然不用改变图像。另外,我可以从图像中提取该数据,并且图片仍然是原始的。为了证明独创性,嵌入散文前后的图像哈希值(SHA 256)仍然是相同的值。
我已经尝试使用stegano
库和piexif
。这是使用piexif
exif_dict = piexif.load(pathImg + 'testImage.jpg')
exif_dict["thumbnail"] = signature # Signature is the 289 bytes of data
exif_bytes = piexif.dump(exif_dict)
piexif.insert(exif_bytes, pathImg + 'testImage.jpg')
我收到一个错误piexif._exceptions.InvalidImageDataError: Given data isn't JPEG.
我自己解决了这个问题,并使用下面的代码插入了值
import piexif
exif_dict = piexif.load('testImageSigned.jpg')
exif_dict["0th"][piexif.ImageIFD.Copyright] = hashValue
exif_bytes = piexif.dump(exif_dict)
piexif.insert(exif_bytes, 'testImageSigned.jpg')
这是要提取的代码:
exif_dict = piexif.load('testImageSigned.jpg')
hashValue2 = exif_dict["0th"][piexif.ImageIFD.Copyright]
Here是exif标记文档,其中描述了数据类型。
[And here是piexif
库文档。
希望这可以帮助您