### Install Stegano Library in Go Source: https://github.com/501urchin/stegano/blob/master/README.md Installs the Stegano library into your Go project using the go get command. This is the first step to using the library's functionalities. ```bash go get github.com/scott-mescudi/stegano@latest ``` -------------------------------- ### Quickstart: Embed File in Go Source: https://github.com/501urchin/stegano/blob/master/README.md A quickstart function to embed a data file into a cover image using Stegano. It takes the cover image path, data file path, output file path, password for encryption, and the bit depth (LSB) as arguments. ```go func main() { err := stegano.EmbedFile("cover.png", "data.txt", stegano.DefaultOutputFile, "password123", stegano.LSB) if err != nil { log.Fatalln("Error:", err) } } ``` -------------------------------- ### Quickstart: Extract File in Go Source: https://github.com/501urchin/stegano/blob/master/README.md A quickstart function to extract embedded data from an image file using Stegano. It requires the path to the image containing embedded data, the password used for encryption, and the bit depth (LSB). ```go func main() { err := stegano.ExtractFile(stegano.DefaultOutputFile, "password123", stegano.LSB) if err != nil { log.Fatalln("Error:", err) } } ``` -------------------------------- ### Manual Encryption and Decryption with Stegano Source: https://context7.com/501urchin/stegano/llms.txt This example shows how to manually encrypt and decrypt data using Stegano's encryption functions, then embed and extract it using the Stegano library. It involves encrypting plaintext, embedding the encrypted data into an image, extracting it, and finally decrypting the extracted data. Error handling is included for each step. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { // Encrypt data manually plaintext := []byte("This is a secret message") password := "myPassword" encryptedData, err := stegano.EncryptData(plaintext, password) if err != nil { log.Fatalf("Encryption failed: %v", err) } fmt.Printf("Original size: %d bytes\n", len(plaintext)) fmt.Printf("Encrypted size: %d bytes (includes 16-byte salt + 12-byte nonce)\n", len(encryptedData)) // Now embed the encrypted data coverImage, _ := stegano.Decodeimage("cover.png") embedder := stegano.NewEmbedHandler() err = embedder.Encode(coverImage, encryptedData, stegano.LSB, "encrypted.png", false) if err != nil { log.Fatalf("Embedding failed: %v", err) } // Extract and decrypt manually extractor := stegano.NewExtractHandler() extractedEncrypted, err := extractor.Decode( coverImage, stegano.LSB, false, // Not compressed ) if err != nil { log.Fatalf("Extraction failed: %v", err) } decrypted, err := stegano.DecryptData(extractedEncrypted, password) if err != nil { log.Fatalf("Decryption failed: %v", err) } fmt.Printf("Decrypted: %s\n", string(decrypted)) } ``` -------------------------------- ### Go Extract Image Data with Decompression using Stegano Source: https://context7.com/501urchin/stegano/llms.txt Extracts compressed byte data from an image using Stegano's `ExtractHandler`. This example demonstrates decoding the image, creating an extract handler, and decoding the data with decompression enabled. It then prints the extracted message. Errors during image loading or data extraction are logged. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { // Load the image containing hidden data embeddedImage, err := stegano.Decodeimage("embedded.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Create an extract handler extractor := stegano.NewExtractHandler() // Extract and decompress the data data, err := extractor.Decode( embeddedImage, // Image with hidden data stegano.MaxBitDepth, // Bit depth used during embedding true, // Data was compressed ) if err != nil { log.Fatalf("Extraction failed: %v", err) } fmt.Printf("Extracted message: %s\n", string(data)) } ``` -------------------------------- ### Image Steganography: Error Handling and Validation (Go) Source: https://context7.com/501urchin/stegano/llms.txt Provides a comprehensive example of image steganography using the Stegano library in Go, focusing on robust error handling and data validation before embedding. It checks image capacity, handles specific errors like 'DataTooLarge' and 'DepthOutOfRange', and demonstrates the use of different bit depths. ```go package main import ( "errors" "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { coverImage, err := stegano.Decodeimage("cover.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } message := []byte("Test message") bitDepth := stegano.MaxBitDepth // Check capacity before embedding capacity := stegano.GetImageCapacity(coverImage, bitDepth) requiredSpace := (len(message) * 8) + 32 // Data + 4-byte header if requiredSpace > capacity*8 { log.Fatalf("Error: Message too large. Need %d bits, have %d bits available", requiredSpace, capacity*8) } embedder := stegano.NewEmbedHandler() err = embedder.Encode(coverImage, message, bitDepth, "output.png", true) // Handle specific errors if err != nil { switch { case errors.Is(err, stegano.ErrDataTooLarge): log.Fatal("Data exceeds image capacity") case errors.Is(err, stegano.ErrDepthOutOfRange): log.Fatal("Invalid bit depth (must be 0-7)") case errors.Is(err, stegano.ErrInvalidCoverImage): log.Fatal("Invalid cover image") case errors.Is(err, stegano.ErrInvalidData): log.Fatal("Invalid data to embed") case errors.Is(err, stegano.ErrFailedToCompressData): log.Fatal("Compression failed") default: log.Fatalf("Embedding failed: %v", err) } } fmt.Println("Embedding successful") } ``` -------------------------------- ### Reed-Solomon Error Correction Encoding and Decoding with Stegano Source: https://context7.com/501urchin/stegano/llms.txt This example demonstrates the use of Reed-Solomon error correction codes independently using the Stegano library. It shows how to encode data with a specified number of parity shards and then decode it to reconstruct the original data, verifying data integrity. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { originalData := []byte("Important data that needs protection") // Encode with 4 parity shards (can recover from 4 errors) encoded, err := stegano.RsEncode(originalData, 4) if err != nil { log.Fatalf("Encoding failed: %v", err) } fmt.Printf("Original size: %d bytes\n", len(originalData)) fmt.Printf("Encoded size: %d bytes (includes 8-byte header + 5 shards)\n", len(encoded)) // Simulate data corruption by modifying some bytes // Reed-Solomon can recover if up to 4 shards are corrupted // Decode and reconstruct decoded, err := stegano.RsDecode(encoded, 4) if err != nil { log.Fatalf("Decoding failed: %v", err) } fmt.Printf("Decoded: %s\n", string(decoded)) fmt.Printf("Data integrity verified: %v\n", string(decoded) == string(originalData)) } ``` -------------------------------- ### Go Embed Image Data with Compression using Stegano Source: https://context7.com/501urchin/stegano/llms.txt Embeds byte data into a cover image using Stegano's `EmbedHandler`. This example specifically enables ZSTD compression for the data before embedding and specifies the maximum bit depth for embedding. The process includes decoding the image, creating an embed handler, encoding the message, and handling potential errors. ```go package main import ( "log" "github.com/scott-mescudi/stegano" ) func main() { // Load the cover image coverImage, err := stegano.Decodeimage("cover.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Create an embed handler embedder := stegano.NewEmbedHandler() // Embed message with compression message := []byte("This is a secret message that will be compressed!") err = embedder.Encode( coverImage, // Cover image message, // Data to embed stegano.MaxBitDepth, // Use bits 0-7 (max capacity) "embedded.png", // Output filename true, // Enable compression ) if err != nil { log.Fatalf("Embedding failed: %v", err) } log.Println("Message embedded successfully") } ``` -------------------------------- ### Go Embed Raw Image Data without Compression using Stegano Source: https://context7.com/501urchin/stegano/llms.txt Embeds raw byte data into a cover image without using compression, utilizing Stegano's `EmbedHandler`. This method is suitable when compression is not needed or desired. The example loads a cover image, creates an embedder, embeds the data using LSB, and saves the resulting image. Error handling is included for image loading, embedding, and saving. ```go package main import ( "log" "github.com/scott-mescudi/stegano" ) func main() { coverImage, err := stegano.Decodeimage("cover.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } embedder := stegano.NewEmbedHandler() // Embed without compression embeddedImage, err := embedder.EmbedDataIntoImage( coverImage, // Cover image []byte("Uncompressed data"), // Raw data stegano.LSB, // Least significant bit ) if err != nil { log.Fatalf("Embedding failed: %v", err) } // Save the result err = stegano.SaveImage("output.png", embeddedImage) if err != nil { log.Fatalf("Save failed: %v", err) } } ``` -------------------------------- ### Embed Message into Image in Go Source: https://github.com/501urchin/stegano/blob/master/README.md Embeds a message into a cover image using Stegano. This example demonstrates decoding the image, creating an embedder, and encoding the message with options for bit depth and output. ```go 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) } } ``` -------------------------------- ### Initialize Concurrent Stegano Handlers (Go) Source: https://github.com/501urchin/stegano/blob/master/README.md Initializes Stegano embedder and extractor handlers with specified concurrency levels (number of goroutines). This can significantly speed up embedding and extraction processes. Returns the handler and an error if initialization fails. ```go embedder, err := stegano.NewEmbedHandlerWithConcurrency(12) if err != nil { log.Fatalln(err) } extractor, err := stegano.NewExtractHandlerWithConcurrency(12) if err != nil { log.Fatalln(err) } ``` -------------------------------- ### Go Import Stegano Package Source: https://context7.com/501urchin/stegano/llms.txt Demonstrates how to import the Stegano package into your Go source files. This import statement is necessary to access the library's functionalities. ```go import "github.com/scott-mescudi/stegano" ``` -------------------------------- ### Embed Data into WAV Audio with Compression (Go) Source: https://context7.com/501urchin/stegano/llms.txt Embeds a byte slice message into a WAV audio file using LSB (Least Significant Bit) steganography with compression. This function takes an input WAV file, an output WAV file path, the message to embed, and the bit depth for embedding. It returns an error if the embedding process fails. ```go package main import ( "log" "github.com/scott-mescudi/stegano" ) func main() { // Create audio embed handler embedder := stegano.NewAudioEmbedHandler() message := []byte("Secret audio message") // Embed with compression using bits 0 to bitDepth err := embedder.EmbedIntoWAVWithDepth( "input.wav", // Input audio file "output.wav", // Output audio file message, // Data to embed stegano.LSB, // Bit depth (0-7) ) if err != nil { log.Fatalf("Audio embedding failed: %v", err) } log.Println("Message embedded in audio successfully") } ``` -------------------------------- ### Go: Benchmark Stegano Sequential vs Concurrent Embedding Source: https://context7.com/501urchin/stegano/llms.txt This Go program benchmarks the performance of sequential versus concurrent data embedding using the stegano library. It measures the time taken for both methods to encode data into an image and calculates the speedup achieved by concurrent processing. Dependencies include the 'stegano' library and standard Go packages for time, runtime, and logging. ```go package main import ( "fmt" "log" "runtime" "time" "github.com/scott-mescudi/stegano" ) func main() { // Load large test image coverImage, err := stegano.Decodeimage("large_test.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Prepare test data testData := make([]byte, 50000) for i := range testData { testData[i] = byte(i % 256) } // Sequential processing sequentialEmbedder := stegano.NewEmbedHandler() start := time.Now() err = sequentialEmbedder.Encode(coverImage, testData, stegano.MaxBitDepth, "seq.png", true) if err != nil { log.Fatalf("Sequential embed failed: %v", err) } sequentialTime := time.Since(start) // Concurrent processing numCPU := runtime.NumCPU() concurrentEmbedder, err := stegano.NewEmbedHandlerWithConcurrency(numCPU) if err != nil { log.Fatalf("Failed to create concurrent embedder: %v", err) } start = time.Now() err = concurrentEmbedder.Encode(coverImage, testData, stegano.MaxBitDepth, "concurrent.png", true) if err != nil { log.Fatalf("Concurrent embed failed: %v", err) } concurrentTime := time.Since(start) // Results fmt.Printf("Performance Benchmark Results:\n") fmt.Printf("Image size: %dx%d pixels\n", coverImage.Bounds().Dx(), coverImage.Bounds().Dy()) fmt.Printf("Data size: %d bytes\n", len(testData)) fmt.Printf("Sequential time: %v\n", sequentialTime) fmt.Printf("Concurrent time (%d cores): %v\n", numCPU, concurrentTime) fmt.Printf("Speedup: %.2fx\n", float64(sequentialTime)/float64(concurrentTime)) } ``` -------------------------------- ### Embed and Extract Data at Specific Bit Depth in WAV (Go) Source: https://context7.com/501urchin/stegano/llms.txt Demonstrates embedding and extracting data from a WAV audio file at a specific bit position (e.g., bit 3) without compression. This allows for more precise control over data hiding. The functions require input/output file paths, the message, and the specific bit position. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { embedder := stegano.NewAudioEmbedHandler() // Embed at bit position 3 (single bit, no compression) err := embedder.EmbedIntoWAVAtDepth( "input.wav", "output_depth3.wav", []byte("Audio secret"), 3, // Use only bit 3 ) if err != nil { log.Fatalf("Embedding failed: %v", err) } // Extract from bit position 3 extractor := stegano.NewAudioExtractHandler() data, err := extractor.ExtractFromWAVAtDepth( "output_depth3.wav", 3, // Extract from bit 3 ) if err != nil { log.Fatalf("Extraction failed: %v", err) } fmt.Printf("Extracted: %s\n", string(data)) } ``` -------------------------------- ### Secure Extraction with Decryption using Stegano Source: https://context7.com/501urchin/stegano/llms.txt This snippet demonstrates how to securely extract and decrypt data from an image using the Stegano library. It requires the image file, the LSB bit depth, and a password for decryption. Errors during loading or extraction are handled. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { embeddedImage, err := stegano.Decodeimage("secure.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Create secure extract handler extractor := stegano.NewSecureExtractHandler() password := "strongPassword123!@#" // Extract, decompress, and decrypt data data, err := extractor.Decode( embeddedImage, // Image with encrypted data stegano.LSB, // Bit depth used password, // Decryption password ) if err != nil { log.Fatalf("Secure extraction failed: %v", err) } fmt.Printf("Decrypted data: %s\n", string(data)) } ``` -------------------------------- ### Concurrent Embedding and Extraction with Stegano Source: https://context7.com/501urchin/stegano/llms.txt This code snippet illustrates how to leverage concurrent processing in the Stegano library to improve embedding and extraction performance. It utilizes `runtime.NumCPU()` to determine the number of available cores and creates concurrent embedders and extractors. Performance is measured using `time.Since`. ```go package main import ( "log" "runtime" "time" "github.com/scott-mescudi/stegano" ) func main() { coverImage, err := stegano.Decodeimage("large_image.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Use all available CPU cores numCPU := runtime.NumCPU() // Create concurrent embedder embedder, err := stegano.NewEmbedHandlerWithConcurrency(numCPU) if err != nil { log.Fatalf("Failed to create embedder: %v", err) } largeData := make([]byte, 100000) // 100KB of data for i := range largeData { largeData[i] = byte(i % 256) } start := time.Now() err = embedder.Encode(coverImage, largeData, stegano.MaxBitDepth, "concurrent.png", true) if err != nil { log.Fatalf("Embedding failed: %v", err) } duration := time.Since(start) log.Printf("Embedding with %d goroutines took %v\n", numCPU, duration) // Create concurrent extractor extractor, err := stegano.NewExtractHandlerWithConcurrency(numCPU) if err != nil { log.Fatalf("Failed to create extractor: %v", err) } start = time.Now() extractedData, err := extractor.Decode(coverImage, stegano.MaxBitDepth, true) if err != nil { log.Fatalf("Extraction failed: %v", err) } duration = time.Since(start) log.Printf("Extraction with %d goroutines took %v\n", numCPU, duration) log.Printf("Extracted %d bytes\n", len(extractedData)) } ``` -------------------------------- ### Embed Data in WAV Audio at Specific Bit Depth (Go) Source: https://github.com/501urchin/stegano/blob/master/README.md Embeds byte data into a WAV audio file at a specified bit depth. Requires input WAV file, output WAV file path, data to embed, and the bit depth. Returns an error if the operation fails. ```go func main() { embedder := stegano.NewAudioEmbedHandler() err := embedder.EmbedIntoWAVAtDepth("input.wav", "output.wav", []byte("Hello World"), 3) if err != nil { log.Fatalln(err) } } ``` -------------------------------- ### Extract Uncompressed Data from Image Source: https://context7.com/501urchin/stegano/llms.txt This Go code snippet demonstrates how to extract uncompressed data that has been hidden within an image using the Stegano library. It loads a PNG image, initializes an extractor, and then retrieves the hidden data. Ensure the 'output.png' file exists and contains embedded data. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { embeddedImage, err := stegano.Decodeimage("output.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } extractor := stegano.NewExtractHandler() // Extract uncompressed data data, err := extractor.ExtractDataFromImage( embeddedImage, // Image with hidden data stegano.LSB, // Bit depth used ) if err != nil { log.Fatalf("Extraction failed: %v", err) } fmt.Printf("Extracted: %s\n", string(data)) } ``` -------------------------------- ### Go Embed and Extract Files with Stegano Source: https://context7.com/501urchin/stegano/llms.txt High-level function to embed a file into an image, applying automatic encryption and compression. It also shows how to extract the hidden file using a password and specified bit depth. Errors during embedding or extraction are logged. ```go package main import ( "log" "github.com/scott-mescudi/stegano" ) func main() { // Embed a file into an image with password protection err := stegano.EmbedFile( "cover.png", // Cover image "secret.txt", // File to hide "output.png", // Output image "mySecurePassword123", // Password for encryption stegano.LSB, // Bit depth (0 = LSB) ) if err != nil { log.Fatalf("Embed failed: %v", err) } // Extract the hidden file err = stegano.ExtractFile( "output.png", // Image with hidden data "mySecurePassword123", // Decryption password stegano.LSB, // Bit depth used for embedding ) if err != nil { log.Fatalf("Extract failed: %v", err) } // File is automatically saved with its original name } ``` -------------------------------- ### Import Stegano Library in Go Source: https://github.com/501urchin/stegano/blob/master/README.md Imports the Stegano library into your Go program. This allows you to access and use the functions and types provided by the library. ```go import ( "github.com/scott-mescudi/stegano" ) ``` -------------------------------- ### Extract Data from WAV Audio at Specific Bit Depth (Go) Source: https://github.com/501urchin/stegano/blob/master/README.md Extracts byte data from a WAV audio file that was embedded at a specific bit depth. Requires the embedded WAV file path and the bit depth used during embedding. Returns the extracted data and an error if the operation fails. ```go func main() { extractor := stegano.NewAudioExtractHandler() data, err := extractor.ExtractFromWAVAtDepth("embedded.wav", 3) if err != nil { log.Fatalln(err) } fmt.Println(string(data)) } ``` -------------------------------- ### Extract Data from WAV Audio with Compression (Go) Source: https://context7.com/501urchin/stegano/llms.txt Extracts hidden data from a WAV audio file that was previously embedded with compression using LSB steganography. This function requires the path to the audio file containing the hidden data and the bit depth used during embedding. It returns the extracted data as a byte slice and an error if the extraction fails. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { // Create audio extract handler extractor := stegano.NewAudioExtractHandler() // Extract and decompress data data, err := extractor.ExtractFromWAVWithDepth( "output.wav", // Audio file with hidden data stegano.LSB, // Bit depth used during embedding ) if err != nil { log.Fatalf("Audio extraction failed: %v", err) } fmt.Printf("Extracted from audio: %s\n", string(data)) } ``` -------------------------------- ### Embed Data at Specific Bit Depth (Single Bit Mode) Source: https://context7.com/501urchin/stegano/llms.txt This Go code demonstrates how to embed data into an image at a specific bit position (e.g., bit 3) using the Stegano library. This single-bit mode offers lower detectability but also less capacity. The code loads a cover image, defines the data to embed, and saves the resulting image. ```go package main import ( "log" "github.com/scott-mescudi/stegano" ) func main() { coverImage, err := stegano.Decodeimage("cover.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } embedder := stegano.NewEmbedHandler() // Embed at bit position 3 (single bit, less capacity but less detectable) embeddedImage, err := embedder.EmbedAtDepth( coverImage, // Cover image []byte("Secret"), // Data to embed 3, // Use only bit 3 ) if err != nil { log.Fatalf("Embedding failed: %v", err) } err = stegano.SaveImage("depth3.png", embeddedImage) if err != nil { log.Fatalf("Save failed: %v", err) } } ``` -------------------------------- ### Embed Data into WAV Audio File Source: https://github.com/501urchin/stegano/blob/master/README.md Embeds data into a WAV audio file using the LSB (Least Significant Bit) method. This function allows for hiding information within audio files, similar to image steganography. It takes the input WAV file, output WAV file path, the data to embed, and the bit depth as parameters. ```go func main() { embedder := stegano.NewAudioEmbedHandler() err := embedder.EmbedIntoWAVWithDepth("input.wav", "output.wav", []byte("Hello World"), stegano.LSB) if err != nil { log.Fatalln(err) } } ``` -------------------------------- ### Securely Embed Data with Encryption and Error Correction Source: https://context7.com/501urchin/stegano/llms.txt This Go snippet shows how to securely embed sensitive data into an image using the Stegano library's secure embed handler. This method incorporates AES-256-GCM encryption, data compression, and Reed-Solomon error correction for robust protection. It requires a cover image, the data to embed, a bit depth, an output filename, and a password for encryption. ```go package main import ( "log" "github.com/scott-mescudi/stegano" ) func main() { coverImage, err := stegano.Decodeimage("cover.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Create secure embed handler (includes encryption, compression, and error correction) embedder := stegano.NewSecureEmbedHandler() sensitiveData := []byte("Top secret information requiring encryption") password := "strongPassword123!@#" err = embedder.Encode( coverImage, // Cover image sensitiveData, // Data to protect stegano.LSB, // Bit depth "secure.png", // Output file password, // Encryption password ) if err != nil { log.Fatalf("Secure embedding failed: %v", err) } log.Println("Data embedded securely with encryption and error correction") } ``` -------------------------------- ### Calculate Image Capacity for Data Embedding Source: https://context7.com/501urchin/stegano/llms.txt This Go code calculates the data embedding capacity of an image using the Stegano library. It loads a cover image and then determines the maximum number of bytes that can be hidden at different bit depths (LSB and MaxBitDepth). The output includes image dimensions and capacity comparisons. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { coverImage, err := stegano.Decodeimage("cover.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } // Calculate capacity at different bit depths capacityLSB := stegano.GetImageCapacity(coverImage, stegano.LSB) capacityMax := stegano.GetImageCapacity(coverImage, stegano.MaxBitDepth) fmt.Printf("Image dimensions: %dx%d\n", coverImage.Bounds().Dx(), coverImage.Bounds().Dy()) fmt.Printf("Capacity at LSB (bit 0): %d bytes\n", capacityLSB) fmt.Printf("Capacity at MaxBitDepth (bits 0-7): %d bytes\n", capacityMax) fmt.Printf("Capacity ratio: %.1fx\n", float64(capacityMax)/float64(capacityLSB)) } ``` -------------------------------- ### Extract Data from Specific Bit Depth Source: https://context7.com/501urchin/stegano/llms.txt This Go snippet shows how to extract data from an image that was embedded at a specific bit depth. It loads the image, initializes an extractor, and specifies the bit depth from which to retrieve the hidden information. This is useful for recovering data embedded using the 'EmbedAtDepth' function. ```go package main import ( "fmt" "log" "github.com/scott-mescudi/stegano" ) func main() { embeddedImage, err := stegano.Decodeimage("depth3.png") if err != nil { log.Fatalf("Failed to load image: %v", err) } extractor := stegano.NewExtractHandler() // Extract from bit position 3 data, err := extractor.ExtractAtDepth( embeddedImage, // Image with hidden data 3, // Extract from bit 3 ) if err != nil { log.Fatalf("Extraction failed: %v", err) } fmt.Printf("Extracted: %s\n", string(data)) } ``` -------------------------------- ### Extract Data from WAV Audio File Source: https://github.com/501urchin/stegano/blob/master/README.md Extracts data hidden within a WAV audio file using the LSB (Least Significant Bit) method. This function is used to retrieve data that was previously embedded into an audio file. It requires the path to the embedded WAV file and the bit depth used for embedding. ```go func main() { extractor := stegano.NewAudioExtractHandler() data, err := extractor.ExtractFromWAVWithDepth("embedded.wav", stegano.LSB) if err != nil { log.Fatalln(err) } fmt.Println(string(data)) } ``` -------------------------------- ### Embed Data into Image Without Compression Source: https://github.com/501urchin/stegano/blob/master/README.md Embeds data into an image without using any compression. This method is useful when preserving the original data integrity is crucial. The data is directly embedded into the LSB of the image pixels. ```go 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) } } ``` -------------------------------- ### Check Image Data Capacity Source: https://github.com/501urchin/stegano/blob/master/README.md Calculates and displays the maximum amount of data an image can hold based on a specified bit depth. This utility function helps in determining the feasibility of hiding a certain amount of information within an image before attempting to embed it. ```go 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) } ``` -------------------------------- ### Embed Data into Image at Specific Bit Depth Source: https://github.com/501urchin/stegano/blob/master/README.md Embeds data into an image at a specific bit depth, offering finer control over the steganography technique. This allows for adjusting the trade-off between data capacity and image imperceptibility. The function takes the cover image, data, and the desired bit depth as input. ```go 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) } } ``` -------------------------------- ### Extract and Decrypt Data from Image Source: https://github.com/501urchin/stegano/blob/master/README.md Extracts encrypted data from an image and then decrypts it using a specific encryption key. This is the complementary function to embedding encrypted data, allowing for secure retrieval and reading of hidden messages. It decodes the data and then applies decryption. ```go 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)) } ``` -------------------------------- ### Extract Data from Image Without Compression Source: https://github.com/501urchin/stegano/blob/master/README.md Extracts data from an image where no compression was used during embedding. This function is the counterpart to embedding without compression, ensuring that the exact data is retrieved. It uses the LSB method for extraction. ```go 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)) } ``` -------------------------------- ### Embed Encrypted Data into Image Source: https://github.com/501urchin/stegano/blob/master/README.md Encrypts data using a provided key and then embeds the encrypted data into an image. This adds an extra layer of security, ensuring that even if the hidden data is detected, it remains unreadable without the decryption key. The embedding process uses the LSB method. ```go 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) } } ``` -------------------------------- ### Extract Message from Image Source: https://github.com/501urchin/stegano/blob/master/README.md Extracts a hidden message from an image using the ExtractHandler class. It decodes the message from the cover file and prints the resulting data as a string. This function assumes the message was embedded using default settings. ```go 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)) } ``` -------------------------------- ### Extract Data from Image at Specific Bit Depth Source: https://github.com/501urchin/stegano/blob/master/README.md Extracts data from an image at a specific bit depth, ensuring that the extraction process matches the embedding parameters. This is crucial for recovering data that was hidden using a particular bit depth. The function requires the embedded image and the bit depth used for embedding. ```go 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)) } ```