
C++を使用したシンプルな画像ステガノグラフィツールで、Least-Significant-Bitエンコーディングを用いてファイルを画像内に暗号化して隠します。
シンプルな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ライセンスの下で提供されています。Copyright © 2022 Zach Collins