stego

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 18 Imported by: 0

README

Stego

Stego is a steganography library written in Go. Steganography allows you to hide data within other files, like images or documents, so they appear unchanged to the naked eye. This library allows you to embed secret messages and extract hidden data from files without anyone knowing the data is there.

Supported file types

  1. PNG
  2. BMP
  3. TIFF
  4. WAV
  5. WebP

Installation

go get github.com/dipakw/stego

Example

Embed secret data into a file

package main

import (
	"github.com/dipakw/stego"
	"fmt"
)

func main() {
	seed := []byte{0x00, 0x0e, 0x03, 0x99}

	file, err := stego.New("path/to/image.png", &stego.Opts{
		RandSeed:  seed,    // Used to randomize the data across the file.
		UseSpace:  0.5,     // How much of the capacity do you want to use? Max is 1.
	})

	// Get the storage capacity in bytes of the file.
	// The .Cap() method is affected by the "UseSpace" option.
	fmt.Println("Storage capacity is", file.Cap(), "bytes.")

	// Prepare the data to be written.
	data := []byte("my-secret-data")

	// Write the data.
	n, err := file.Write(data)

	if err != nil {
		fmt.Println("Failed to write:", err)
		return
	}

	fmt.Println("Written", n, "bytes.")

	// Save the updated file.
	err = file.Save("path/to/new.png")

	if err != nil {
		fmt.Println("Failed to save the file:", err)
		return
	}

	fmt.Println("Saved successfully.")
}

Read embedded data from a file

package main

import (
	"github.com/dipakw/stego"
	"fmt"
)

func main() {
	seed := []byte{0x00, 0x0e, 0x03, 0x99}

	file, err := stego.New("path/to/new.png", &stego.Opts{
		RandSeed:  seed,    // Used to randomize the data across the file.
		UseSpace:  0.5,     // How much of the capacity do you want to use? Max is 1.
	})

	data := make([]byte, 14)

	n, err := file.Read(data)

	if err != nil {
		fmt.Println("Failed to read:", err)
		return
	}

	fmt.Println("Data:", string(data[:n]))
}

TODO

  • Implement encryption (currently the Encrypted and SecretKey options are defined but not used).

Disclaimer

This software is provided for good purposes only. Users are liable for any harmful or illegal use of this library. The authors and contributors are not responsible for any misuse of this software. Use at your own risk and ensure compliance with all applicable laws.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocateImagePx

func LocateImagePx(width, height int, byteOffet int64) (x, y, rgb int)

func LocateImagePxByBitIdx

func LocateImagePxByBitIdx(width, height, bitIdx int) (x, y, rgb int)

func Permutation

func Permutation(seedBytes []byte, from, to int) []int

Types

type BitReader

type BitReader struct {
	BB []byte // Bytes to be read.
	BI int    // Byte index to be read.
	II int    // Bit index to be read in the current byte.
}

func (*BitReader) Next

func (r *BitReader) Next() uint8

func (*BitReader) Reset

func (r *BitReader) Reset()

type File

type File interface {
	Seek(n int64, w int) (int64, error)
	Read(dst []byte) (n int, err error)
	Write(b []byte) (n int, err error)
	WriteOrd(ord []int, b []byte) (n int, err error)
	ReadOrd(ord []int, dst []byte, size int) (n int, err error)
	Offset() int64
	Cap() int64
	Save(path string) error
}

func NewBMP

func NewBMP(path string) (File, error)

func NewPNG

func NewPNG(path string) (File, error)

func NewTIFF

func NewTIFF(path string) (File, error)

func NewWAV

func NewWAV(path string) (File, error)

func NewWEBP

func NewWEBP(path string) (File, error)

type Image

type Image struct {
	// contains filtered or unexported fields
}

func NewImage

func NewImage(opts *ImageOpts) (*Image, error)

func (*Image) Cap

func (file *Image) Cap() int64

func (*Image) Offset

func (file *Image) Offset() int64

func (*Image) Read

func (file *Image) Read(dst []byte) (int, error)

func (*Image) ReadOrd

func (file *Image) ReadOrd(ord []int, dst []byte, size int) (int, error)

func (*Image) Save

func (file *Image) Save(path string) error

func (*Image) Seek

func (file *Image) Seek(offset int64, w int) (int64, error)

func (*Image) Write

func (file *Image) Write(p []byte) (int, error)

func (*Image) WriteOrd

func (file *Image) WriteOrd(ord []int, p []byte) (int, error)

type ImageOpts

type ImageOpts struct {
	Path   string
	SaveFN func(mu *sync.Mutex, rgba *image.RGBA, path string) error
	Decode func(r io.Reader) (img image.Image, err error)
}

type Opts

type Opts struct {
	RandSeed  []byte
	UseSpace  float64
	Encrypted bool
	SecretKey []byte
}

type Stego

type Stego interface {
	Read(dst []byte) (n int, err error)
	Write(b []byte) (n int, err error)
	Cap() int64
	Save(path string) error
	File() File
	Size() (int, error)
}

func New

func New(path string, opts *Opts) (Stego, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func (*Store) Cap

func (s *Store) Cap() int64

func (*Store) File

func (s *Store) File() File

func (*Store) Read

func (s *Store) Read(dst []byte) (n int, err error)

func (*Store) Save

func (s *Store) Save(path string) error

func (*Store) Size

func (s *Store) Size() (int, error)

func (*Store) Write

func (s *Store) Write(b []byte) (n int, err error)

type WAV

type WAV struct {
	// contains filtered or unexported fields
}

func (*WAV) Cap

func (f *WAV) Cap() int64

func (*WAV) Offset

func (f *WAV) Offset() int64

func (*WAV) Read

func (f *WAV) Read(dst []byte) (int, error)

func (*WAV) ReadOrd

func (file *WAV) ReadOrd(ord []int, b []byte, size int) (int, error)

func (*WAV) Save

func (f *WAV) Save(path string) error

func (*WAV) Seek

func (f *WAV) Seek(offset int64, whence int) (int64, error)

func (*WAV) Write

func (f *WAV) Write(p []byte) (int, error)

func (*WAV) WriteOrd

func (file *WAV) WriteOrd(ord []int, b []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL