Stegano
A fast steganography library built for go
Install / Use
/learn @501urchin/SteganoREADME
Stegano: The fastest Steganography Library for Go
Table of Contents
- Features
- What is Steganography?
- Use Cases
- Installation
- Usage
- Working with Images
- Working with Audio
- Advanced Options
- Notes
- Benchmarks
- Future Improvements
Features
- Multi-Image Support: Works with any image type compatible with Go's
image.Image. - Data Compression: Supports ZSTD compression to minimize the size of embedded data.
- Reed-Solomon Codes: Implements Reed-Solomon error correction.
- Capacity Calculation: Automatically calculates the maximum capacity of an image for data embedding.
- Variable Depth Encoding: Allows you to embed data up to a specified bit depth.
- Concurrency: Supports concurrent processing for improved speed (higher memory usage).
- Custom Bit Depth Embedding: Lets you specify the bit depth used for data embedding (e.g., LSB, MSB).
- Encryption: Enables secure encryption of data before embedding into the image.
- Efficient PNG Encoding: Saves the image in PNG format.
What is Steganography?
Steganography is the practice of concealing data within other, seemingly innocent data in such a way that it remains undetectable to the casual observer. Unlike encryption, which focuses on making data unreadable, steganography hides it entirely, making the data appear normal and undisturbed.
The most common use case for steganography is hiding text or binary data within an image. This library enables you to easily embed and extract such hidden information from images.
Installation
To integrate Stegano into your Go project, simply run:
go get github.com/scott-mescudi/stegano@latest
Usage
Import the Library
import (
"github.com/scott-mescudi/stegano"
)
Working with Images
Quickstart
The following are high-level functions for embedding and extracting data easily:
func main() {
err := stegano.EmbedFile("cover.png", "data.txt", stegano.DefaultOutputFile, "password123", stegano.LSB)
if err != nil {
log.Fatalln("Error:", err)
}
}
func main() {
err := stegano.ExtractFile(stegano.DefaultOutputFile, "password123", stegano.LSB)
if err != nil {
log.Fatalln("Error:", err)
}
}
For more control over the process, refer to the examples below:
1. Embed a Message into an Image
You can embed a message into an image using the EmbedHandler class.
func main() {
// wrapper function around different image decoders.
coverFile, err := stegano.Decodeimage("coverimage.png")
if err != nil {
log.Fatalln(err)
}
embedder := stegano.NewEmbedHandler()
// Encode and save the message in the cover image.
err = embedder.Encode(coverFile, []byte("Hello, World!"), stegano.MaxBitDepth, stegano.DefaultOutputFile, true)
if err != nil {
log.Fatalln(err)
}
}
2. Extract a Message from an Embedded Image
Extract a hidden message from an image using the ExtractHandler class.
func main() {
coverFile, err := stegano.Decodeimage("embeddedimage.png")
if err != nil {
log.Fatalln(err)
}
extractor := stegano.NewExtractHandler()
// Decode the message from the image.
data, err := extractor.Decode(coverFile, stegano.MaxBitDepth, true)
if err != nil {
log.Fatalln(err)
}
// Print the extracted message.
fmt.Println(string(data))
}
3. Embed Data Without Compression
Embed data into an image without using any compression.
func main() {
coverFile, err := stegano.Decodeimage("coverimage.png")
if err != nil {
log.Fatalln(err)
}
embedder := stegano.NewEmbedHandler()
// Embed the message into the image without compression.
embeddedImage, err := embedder.EmbedDataIntoImage(coverFile, []byte("Hello, World!"), stegano.LSB)
if err != nil {
log.Fatalln(err)
}
err = stegano.SaveImage(stegano.DefaultOutputFile, embeddedImage)
if err != nil {
log.Fatalln(err)
}
}
4. Extract Data Without Compression
Extract data from an image where no compression was used.
func main() {
coverFile, err := stegano.Decodeimage("embeddedimage.png")
if err != nil {
log.Fatalln(err)
}
extractor := stegano.NewExtractHandler()
// Extract uncompressed data from the image.
data, err := extractor.ExtractDataFromImage(coverFile, stegano.LSB)
if err != nil {
log.Fatalln(err)
}
// Print the extracted message.
fmt.Println(string(data))
}
5. Embed at a Specific Bit Depth
Embed data at a specific bit depth for better control over the hiding technique.
func main() {
coverFile, err := stegano.Decodeimage("coverimage.png")
if err != nil {
log.Fatalln(err)
}
embedder := stegano.NewEmbedHandler()
// Embed the message at a specific bit depth (e.g., 3).
embeddedImage, err := embedder.EmbedAtDepth(coverFile, []byte("Hello, World!"), 3)
if err != nil {
log.Fatalln(err)
}
err = stegano.SaveImage(stegano.DefaultOutputFile, embeddedImage)
if err != nil {
log.Fatalln(err)
}
}
6. Extract Data from a Specific Bit Depth
Extract data from an image using the same bit depth used for embedding.
func main() {
coverFile, err := stegano.Decodeimage("embeddedimage.png")
if err != nil {
log.Fatalln(err)
}
extractor := stegano.NewExtractHandler()
// Extract data from the image at a specific bit depth (e.g., 3).
data, err := extractor.ExtractAtDepth(coverFile, 3)
if err != nil {
log.Fatalln(err)
}
// Print the extracted message.
fmt.Println(string(data))
}
7. Check Image Capacity
Check how much data an image can hold based on the bit depth.
func main() {
coverFile, err := stegano.Decodeimage("embeddedimage.png")
if err != nil {
log.Fatalln(err)
}
// Calculate and print the data capacity of the image.
capacity := stegano.GetImageCapacity(coverFile, stegano.MaxBitDepth)
fmt.Printf("Image capacity at bit depth %d: %d bytes\n", stegano.MaxBitDepth, capacity)
}
8. Embed Encrypted Data
Encrypt the data before embedding it into the image for added security.
func main() {
coverFile, err := stegano.Decodeimage("coverimage.png")
if err != nil {
log.Fatalln(err)
}
// Encrypt the data before embedding.
encryptedData, err := stegano.EncryptData([]byte("Hello, World!"), "your-encryption-key")
if err != nil {
log.Fatalln(err)
}
embedder := stegano.NewEmbedHandler()
// Embed the encrypted data into the image.
err = embedder.Encode(coverFile, encryptedData, stegano.LSB, stegano.DefaultOutputFile, true)
if err != nil {
log.Fatalln(err)
}
}
9. Extract and Decrypt Data
Extract encrypted data from the image and decrypt it.
func main() {
coverFile, err := stegano.Decodeimage("embeddedimage.png")
if err != nil {
log.Fatalln(err)
}
extractor := stegano.NewExtractHandler()
// Extract the encrypted data.
encryptedData, err := extractor.Decode(coverFile, stegano.LSB, true)
if err != nil {
log.Fatalln(err)
}
// Decrypt the data.
decryptedData, err := stegano.DecryptData(encryptedData, "your-encryption-key")
if err != nil {
log.Fatalln(err)
}
// Print the decrypted message.
fmt.Println(string(decryptedData))
}
Working with Audio
1. Embed Data into WAV Files
func main() {
embedder := stegano.NewAudioEmbedHandler()
err := embedder.EmbedIntoWAVWithDepth("input.wav", "output.wav", []byte("Hello World"), stegano.LSB)
if err != nil {
log.Fatalln(err)
}
}
2. Extract Data from WAV Files
func main() {
extractor := stegano.NewAudioExtractHandler()
data, err := extractor.ExtractFromWAVWithDepth("embedded.wav", stegano.LSB)
if err != nil {
log.Fatalln(err)
}
fmt.Println(string(data))
}
3. Embed at Specific Bit Depth
func main() {
embedder := stegano.NewAudioEmbedHandler()
err := embedder.EmbedIntoWAVAtDepth("input.wav", "output.wav", []byte("Hello World"), 3)
if err != nil {
log.Fatalln(err)
}
}
4. Extract from Specific Bit Depth
func main() {
extractor := stegano.NewAudioExtractHandler()
data, err := extractor.ExtractFromWAVAtDepth("embedded.wav", 3)
if err != nil {
log.Fatalln(err)
}
fmt.Println(string
