Stego is a command-line interface for encoding and decoding secret data in images, using the Least Significant Bit (LSB) steganography technique. Currently, Stego only supports PNG images, but is able to hide any type of data and files.
Stego achieves this by first prepending the size of the secret data to the data itself. It then writes each bit of the data to the least significant bit of each pixel's RGB values in the image. When Stego decodes an image, it collects each least significant bit of the image, then recompose the bits back into data. The first 8 LSB will tell Stego the total size of the hidden data.
Stego is also available as a Go package.
$ go get -u github.com/gzcharleszhang/stego
$ stego encode ./stego/example.png --data "Stego is a steganography CLI tool."
By default, Stego will add a -out
suffix to the output image. For example, the above encoded image
can be found at ./stego/example-out.png
To specify an output path, use the --out
or -o
flag
$ stego encode ./stego/example.png -d "Stego is a steganography CLI tool." -o ./out/example.png
Use the --bits
or -b
flag to specify the number
of bits in a byte used for encoding.
For example, this will tell Stego to use up to 2 bits per byte. If Stego already used all of the least significant bits in an image but there is still more data to encode, then Stego will encode using the second least significant bit.
$ stego encode ./stego/example.png -d "Stego is a steganography CLI tool." -b 2
$ stego decode ./example.png
Stego is a steganography CLI tool.
Before encoding data in an image, you may want to know how much hidden data an image can hold.
Stego has a size
command that calculates the
maximum encoding size of an image in bytes.
$ stego size ./example.png
1179644
Use the --bits
or -b
flag to specify the number
of bits in a byte used for encoding.
$ stego size ./example.png -b 2
2359292
Pretty print using the --pretty
or -p
flag.
$ stego size --pretty ./example.png
1.12 MB
$ go get -u github.com/gzcharleszhang/stego/pkg/stegolsb
Stego can encode data into an image from the Go image package
import (
"fmt"
"github.com/gzcharleszhang/stego/pkg/stegolsb"
"image"
"image/png"
"os"
)
func main() {
// read image from file
file, _ := os.Open("/path/to/image")
img, _, _ := image.Decode(file)
// encode data using Stego
outImg, err := stego_lsb.LSBEncode(img, "Hello, world!")
if err != nil {
fmt.Printf("Error encoding data: %v\n", err)
}
}
The package also supports encoding with multiple bits per byte. This allows the image to encode more data, however it will decrease the encoded image quality compared to the original image.
Stego will first use the least significant bit, then the second least significant bit, and so on.
Encoding an image using up to 2 bit per byte
outImg, err := stego_lsb.Encode(img, "Hello, world!", 2)
if err != nil {
fmt.Printf("Error encoding data: %v\n", err)
}
Stego attempts to decode an image and prints the hidden data.
data, err := stego_lsb.Decode(img)
if err != nil {
fmt.Printf("Error decoding image: %v\n", err)
}
Stego can calculate the maximum number of bytes available for encoding in an image.
maxSize, err := stego_lsb.MaxLSBEncodeSize(img)
if err != nil {
fmt.Printf("Error getting max encode size: %v", err)
}
Use stego_lsb.MaxEncodeSize
to get the max size if using
more than 1 bit per byte for encoding.
The maximum number of bytes available in the image when using up to 2 bits per byte for encoding.
maxSize, err := stego_lsb.MaxEncodeSize(img, 2)
if err != nil {
fmt.Printf("Error getting max encode size: %v", err)
}