Image steganography with Rust
This Rust program allows you to hide a text message within an image using the Least Significant Bit (LSB) replacement technique. The LSB replacement technique involves altering the least significant bits of the image's pixels to encode the hidden message. This technique is a form of steganography, which is the practice of concealing one piece of information within another.
See this whitepaper for reference
-
Encoding Functions: You can use the
encode_from_u8_array,encode_from_path(or lower levelencode_from_image) functions to embed a text message into an image using LSB replacement. Always outputs PNG format for reliable steganography. -
Decoding Functions: The
decode_from_u8_array,decode_from_path(or lower leveldecode_from_image) function allows you to extract the hidden message from an encoded image.
- Add
img_steganoas agitdependency in yourCargo.toml.
[dependencies]
img_stegano = {git = "https://github.com/collinsmuriuki/img_stegano.git"}- Import the
ImgSteganoto use as demonstrated in the following example:
use img_stegano::{encode_from_image, decode_from_image, Image, image::ImageFormat};
let image = Image::open("dice.png").expect("Failed to open image");
let encoded = encode_from_image(image, "foo bar").expect("Failed to encode");
encoded.save("out.png", ImageFormat::Png).expect("Failed to save image");
let encoded = Image::open("out.png").expect("Failed to open image");
let decoded_text = decode_from_image(&encoded).expect("Failed to decode");
assert_eq!(decoded_text, "foo bar");use std::{fs::File, io::Read};
use img_stegano::{encode_from_u8_array, decode_from_u8_array};
let mut file = File::open("dice.png").expect("Failed to open file");
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
let encoded = encode_from_u8_array(&buffer, "foo bar").expect("Failed to encode");
std::fs::write("out.png", &encoded).expect("Failed to save");
let decoded_text = decode_from_u8_array(&encoded).expect("Failed to decode");
assert_eq!(decoded_text, "foo bar");use img_stegano::{encode_from_path, decode_from_path, image::ImageFormat};
let encoded = encode_from_path("dice.png", "foo bar").expect("Failed to encode");
encoded.save("out.png", ImageFormat::Png).expect("Failed to save image");
let decoded_text = decode_from_path("out.png").expect("Failed to decode");
assert_eq!(decoded_text, "foo bar");You can interact with this program in your command line by installing via cargo:
cargo install --git https://github.com/c12i/img_stegano.gitEncode (automatically creates dice-encoded.png):
img_stegano_cli encode --input "dice.png" --message "foo bar"Decode:
img_stegano_cli decode --input "dice-encoded.png"Get capacity:
img_stegano_cli capacity --input "dice.png"This project is licensed under the MIT License. Feel free to contribute, report issues, or suggest improvements. Enjoy using ImgStegano for image steganography!