Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stego-lib

A library for hiding and extracting secret data in files (specifically PNG/BMP).

About the Library

stego-lib provides a simple, extensible interface for steganography:

  • Algorithms (currently LSB) read/write bits in a container (e.g., image pixels).
  • Adapters (e.g., ImageAdapter) parse a specific container format and provide raw bytes to the algorithm.

Features

  • Supported algorithm: LSB (Least Significant Bit).
  • Analysis: Mean Squared Error (MSE) in the analysis module.
  • Supported container formats via ImageAdapter: PNG, BMP (using the image crate).

Quick Start

  1. Installing the Library from GitHub You can add stego-lib directly from GitHub in your Cargo.toml:
[dependencies]
stego-lib = { git = "https://github.com/Chardje/stego-lib.git" }

Then run cargo build to fetch and compile the library. After that, you can use the library in your Rust project as shown in the examples above.

  1. Initialize the adapter registry

Before use, initialize the global adapter registry once:

use std::sync::Mutex;
use stego_lib::adapters::ImageAdapter;

stego_lib::ADAPTERS.set(Mutex::new(vec![ImageAdapter::create]));
  1. Hiding data (hide)
use std::fs::File;
use std::io::Cursor;
use stego_lib::algorithms::LSBAlgorithm;

let container_file = File::open("tests/teststego.png")?;
let secret = Cursor::new(b"Hello, world!".to_vec());
let mut stego = stego_lib::hide::<_, _, LSBAlgorithm>(container_file, secret)?;
// `stego` — Cursor<Vec<u8>> with the modified container bytes
  1. Extracting data (extract)
use std::fs::File;
use stego_lib::algorithms::LSBAlgorithm;

let container_file = File::open("tests/out.png")?;
let mut secret_cursor = stego_lib::extract::<_, LSBAlgorithm>(container_file)?;
let mut secret = Vec::new();
secret_cursor.read_to_end(&mut secret)?;
// `secret` now contains the extracted hidden data

Implementation Details

  • ADAPTERS — global OnceLock<Mutex<Vec<AdapterCtor>>> storing adapter constructors.
  • ImageAdapter decodes images into an RGBA buffer, provides access via readeble_mut_data(), and re-encodes PNG through export().
  • The LSB algorithm in src/algorithms/lsb.rs stores the secret length in the first 64 bytes (one bit per byte), followed by the secret bits (1 secret bit per container byte).

Examples and CLI

Build and Test

  • Build: cargo build
  • Run tests: cargo test
  • CLI example: cargo run --example cli -- hide -c tests/teststego.png -s "Hello" -o tests/out.png -a lsb

Additional Notes

To support other formats or algorithms, implement a new adapter (constructor function fn(&Vec<u8>) -> Result<Box<dyn IAdapter>, Box<dyn Error>>) and add it to ADAPTERS.

About

A library for hiding and extracting secret data in files

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages