简单的 C++ 加密与隐写工具,使用密码保护加密来保护文件内容,然后通过最低有效位编码将其嵌入图像的像素数据中。适用于 Linux、MacOS 和 Windows 系统。
$ ./steganography encode -i data/orig.png -e data/jekyll_and_hyde.zip -o output.png
Password: 1234
* Image size: 640x426 pixels
* Encoding level: Low (Default)
* Max embed size: 132.38 KiB
* Embed size: 61.77 KiB
* Encrypted embed size: 61.78 KiB
* Generated CRC32 checksum
* Generated encryption key with PBKDF2-HMAC-SHA-256 (20000 rounds)
* Encrypted embed with AES-256-CBC
* Embedded jekyll_and_hyde.zip into image
* Successfully wrote to output.png

包含整本书《Dr Jekyll and Mr Hyde》全部内容的嵌入 ZIP 的图像:

$ ./steganography decode -i output.png -o "out - jekyll_and_hyde.zip"
Password: 1234
* Image size: 640x426 pixels
* Generated decryption key with PBKDF2-HMAC-SHA-256 (20000 rounds)
* Successfully decrypted header
* File signatures match
* Detected embed jekyll_and_hyde.zip
* Encoding level: Low (Default)
* Encrypted embed size: 61.78 KiB
* Successfully decrypted the embed
* Decrypted embed size: 61.77 KiB
* CRC32 checksum matches
* Successfully wrote to out - jekyll_and_hyde.zip
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ make -j 4
Usage: steganography [-h] {decode,encode}
Optional arguments:
-h, --help shows help message and exits
-v, --version prints version information and exits
Subcommands:
decode Decodes and extracts an embed-file from an image
encode Encodes an embed-file into an image
Usage: encode [-h] --input VAR --output VAR --embed VAR [--passwd VAR]
Encodes an embed-file into an image
Optional arguments:
-h, --help shows help message and exits
-v, --version prints version information and exits
-i, --input specify the input image. [required]
-o, --output specify the output image. [required]
-e, --embed specify the file to embed. [required]
-p, --passwd specify the encryption password.
Usage: decode [-h] --input VAR [--output VAR] [--passwd VAR]
Decodes and extracts an embed-file from an image
Optional arguments:
-h, --help shows help message and exits
-v, --version prints version information and exits
-i, --input specify the input image. [required]
-o, --output specify the output file. [default: ""]
-p, --passwd specify the encryption password.
该程序首先通过读取 /dev/urandom 中的二进制数据,随机生成一个 128 位密码盐 和一个 128 位 AES 初始化向量。 然后,它将该 密码盐 作为参数,通过对用户输入的字符串使用 PBKDF2-HMAC-SHA-256 来生成加密密钥。 接着计算待嵌入文件的 CRC32 哈希值,并将其存储在头部中,作为数据有效性的校验和。 随后,它使用 PKCS #7 算法对待嵌入文件的二进制数据进行填充,然后使用先前生成的 初始化向量,以 CBC 模式 下的 AES-256 实际加密头部和填充后的数据。 现在,数据通过首先选取一个随机偏移量,然后遍历数据的每一位并将其存储在实际的图像像素数据中,从而真正编码到图像内部,这是通过设置每个像素每个通道字节的 最低有效位 来实现的。
解码过程与上述编码过程完全相同,只是反向进行。 唯一的区别在于,解码时,程序在尝试提取并解密数据后,会比较头部部分中的一些信息,以尝试验证提取过程。所比较的头部字段为:本程序自定义的 4 字节文件签名,以及解密数据的 CRC32 哈希值。 如果这些字段中有任何一个与其正确值不匹配,解密过程将失败。这仅会在以下情况下发生:你尝试解密的文件实际上不包含嵌入数据、你输入的密码错误,或者图像文件以某种方式损坏。
虽然检测图像中是否嵌入了数据是一项简单的任务,但理论上无法得知是本程序所为,并且理论上在不知道密码的情况下,应该没有已知的方法可以解密数据,除非在此过程中花费数百万年。
请勿使用本程序加密和隐藏你希望远离窥探的重要数据。这只是一个我出于兴趣制作的简单概念验证程序。 我不是密码学家,只是一个爱好者,使用风险自负。
本软件根据 MIT 许可证授权。版权所有 © 2022 Zach Collins