Expand description
§PNGer - PNG Steganography Library
PNGer is a Rust library for embedding and extracting payloads within PNG images using steganography techniques. It provides both file-based and memory-based APIs for flexibility, with support for various embedding strategies and payload obfuscation methods.
§Key Features
- Embedding Strategies: For now, only LSB (Least Significant Bit) strategy is supported with linear and random patterns
- Payload Obfuscation: XOR encryption for additional security
- Cross-platform: Compatible across different architectures
- Password Protection: Derive embedding patterns from passwords
§Quick Start
§Basic embedding and extraction from files
use pnger::{embed_payload_from_file, extract_payload_from_file};
// Embed a payload
let payload = b"this is a payload";
let png_with_payload = embed_payload_from_file("image.png", payload)?;
std::fs::write("output.png", png_with_payload)?;
// Extract the payload
let extracted_payload = extract_payload_from_file("output.png")?;
assert_eq!(extracted_payload, payload);§Basic embedding and extraction from bytes
use pnger::{embed_payload_from_bytes, extract_payload_from_bytes};
// Embed a payload
let payload = b"this is a payload";
let png_bytes = [137u8, 80u8, 78u8, 71u8, 13u8, 10u8, 26u8, 10u8, /* ... */];
let png_with_payload = embed_payload_from_bytes(&png_bytes, payload)?;
// Extract the payload
let extracted_payload = extract_payload_from_bytes(&png_with_payload)?;
assert_eq!(&extracted_payload, payload);§Advanced Usage with Options
use pnger::{embed_payload_from_file_with_options, EmbeddingOptions, Strategy};
use pnger::strategy::lsb::{LSBConfig, BitIndex};
use pnger::Obfuscation;
// Configure random pattern with password protection and XOR obfuscation
let strategy = Strategy::LSB(
LSBConfig::random()
.with_password("my_secret_password".to_string())
.with_bit_index(BitIndex::Bit1)
);
let options = EmbeddingOptions::new_with_obfuscation(
strategy,
Obfuscation::Xor { key: b"encryption_key".to_vec() }
);
let payload = b"highly secure secret message";
let result = embed_payload_from_file_with_options("image.png", payload, options)?;§Fluent Builder API
The fluent builder API provides an ergonomic way to configure embedding options:
use pnger::{embed_payload_from_file_with_options, EmbeddingOptions};
use pnger::strategy::lsb::BitIndex;
// Simple linear embedding with XOR encryption
let options = EmbeddingOptions::linear()
.with_xor_string("my_encryption_key");
// Random embedding with password and custom bit index
let options = EmbeddingOptions::random_with_password("secure_password")
.with_bit_index(BitIndex::Bit2)
.with_xor_key(b"additional_layer".to_vec());
// Conditional configuration
let password = Some("secret".to_string());
let options = EmbeddingOptions::random()
.with_password_if_some(password)
.with_xor_string("encryption_key");
let payload = b"fluent API example";
let result = embed_payload_from_file_with_options("image.png", payload, options)?;§Embedding Strategies
§LSB (Least Significant Bit)
The primary embedding strategy modifies the least significant bits of image pixels:
- Linear Pattern: Sequential pixel modification (faster, less secure)
- Random Pattern: Pseudo-random pixel selection (slower, more secure)
- Password Protection: Derive random patterns from passwords
- Bit Index Selection: Choose which bit position to modify (0-7)
§Considerations
- Capacity: 1 byte requires 8 pixels (1 bit per pixel for LSB)
- Random Patterns: Slightly slower due to PRNG operations
§Error Handling
All functions return Result<T, PngerError> with comprehensive error types:
- Capacity Errors: Payload too large for image
- I/O Errors: File system or PNG format issues
- Crypto Errors: Random number generation or password derivation failures
- Format Errors: Invalid PNG structure or corrupted data
Re-exports§
pub use crate::obfuscation::Obfuscation;pub use crate::strategy::Strategy;pub use error::PngerError;
Modules§
- error
- Error types for PNGer Steganography Operations
- obfuscation
- Payload Obfuscation for Enhanced Security
- strategy
- Steganography strategy configuration for payload embedding.
Structs§
- Embedding
Options - Configuration options for payload embedding and extraction operations.
Functions§
- embed_
payload_ from_ bytes - Embeds a payload into PNG data in memory using the default embedding strategy.
- embed_
payload_ from_ bytes_ with_ options - Embeds a payload into PNG data using custom embedding options.
- embed_
payload_ from_ file - Embeds a payload into a PNG file using the default embedding strategy.
- embed_
payload_ from_ file_ with_ options - Embeds a payload into a PNG file using custom embedding options.
- extract_
payload_ from_ bytes - Extracts a payload from PNG data in memory using the default embedding strategy.
- extract_
payload_ from_ bytes_ with_ options - Extracts a payload from PNG data using custom embedding options.
- extract_
payload_ from_ file - Extracts a payload from a PNG file using the default embedding strategy.
- extract_
payload_ from_ file_ with_ options - Extracts a payload from a PNG file using custom embedding options.