steganography

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: MIT Imports: 6 Imported by: 17

README

Steganography Lib

GoDoc Go Report Card LICENSE MIT Actions CI codecov Mentioned in Awesome Go

Steganography is a library written in Pure go to allow simple LSB steganography on images. It is capable of both encoding and decoding images. It can store files of any format. This library is inspired by Stego by EthanWelsh, a command line utility with the same purpose.

Installation

go get -u github.com/auyer/steganography

Demonstration

Original Encoded
Original File Encoded File

The second image contains the first paragraph of the description of a stegosaurus on Wikipedia, also available in examples/message.txt as an example.


Getting Started

package main
import (
    "bufio"
    "image/png"
    "io/ioutil"

    "github.com/auyer/steganography"
)

Encode

Write mode is used to take a message and embed it into an image file using LSB steganography in order to produce a secret image file that will contain your message.

Note that the minimum image size is 24 pixels for one byte. For each additional byte, it is necessary 3 more pixels.

inFile, _ := os.Open("input_file.png") // opening file
reader := bufio.NewReader(inFile)   // buffer reader 
img, _ := png.Decode(reader)   // decoding to golang's image.Image

w := new(bytes.Buffer)   // buffer that will recieve the results
err := steganography.Encode(w, img, []byte("message")) // Encode the message into the image
if err != nil {
    log.Printf("Error Encoding file %v", err)
    return
}
outFile, _ := os.Create("out_file.png") // create file
w.WriteTo(outFile) // write buffer to it
outFile.Close()

note: all error checks were removed for brevity, but they should be included.

Size of Message

Length mode can be used in order to preform a preliminary check on the carrier image in order to deduce how large of a file it can store.

sizeOfMessage := steganography.GetMessageSizeFromImage(img) // retrieves the size of the encoded message

Decode

Read mode is used to read an image that has been encoded using LSB steganography, and extract the hidden message from that image.

inFile, _ := os.Open(encodedInputFile) // opening file
defer inFile.Close()

reader := bufio.NewReader(inFile) // buffer reader 
img, _ := png.Decode(reader) // decoding to golang's image.Image

sizeOfMessage := steganography.GetMessageSizeFromImage(img) // retrieving message size to decode in the next line

msg := steganography.Decode(sizeOfMessage, img) // decoding the message from the file
fmt.Println(string(msg))

note: all error checks were removed for brevity, but they should be included.

Complete Example

For a complete example, see the examples/stego.go file. It is a command line app based on the original fork of this repository, but modified to use the Steganography library.


Attributions

Documentation

Overview

Package steganography is a library that provides functions to execute steganography encoding and decoding in a given image. It is also able to check the maximum encoding size, and the size of an encoded message.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(msgLen uint32, pictureInputFile image.Image) (message []byte)

Decode gets messages from pictures using LSB steganography, decode the message from the picture and return it as a sequence of bytes It wraps EncodeNRGBA making the conversion from image.Image to image.NRGBA

Input:
	msgLen uint32 : size of the message to be decoded
	pictureInputFile image.Image : image data used in decoding
Output:
	message []byte decoded from image

func Encode

func Encode(writeBuffer *bytes.Buffer, pictureInputFile image.Image, message []byte) error

Encode encodes a given string into the input image using least significant bit encryption (LSB steganography) The minnimum image size is 23 pixels It wraps EncodeNRGBA making the conversion from image.Image to image.NRGBA

Input:
	writeBuffer *bytes.Buffer : the destination of the encoded image bytes
	message []byte : byte slice of the message to be encoded
	pictureInputFile image.Image : image data used in encoding
Output:
	bytes buffer ( io.writter ) to create file, or send data.

func EncodeNRGBA added in v1.0.1

func EncodeNRGBA(writeBuffer *bytes.Buffer, rgbImage *image.NRGBA, message []byte) error

EncodeNRGBA encodes a given string into the input image using least significant bit encryption (LSB steganography) The minnimum image size is 24 pixels for one byte. For each additional byte, it is necessary 3 more pixels.

Input:
	writeBuffer *bytes.Buffer : the destination of the encoded image bytes
	pictureInputFile image.NRGBA : image data used in encoding
	message []byte : byte slice of the message to be encoded
Output:
	bytes buffer ( io.writter ) to create file, or send data.

func GetMessageSizeFromImage

func GetMessageSizeFromImage(pictureInputFile image.Image) (size uint32)

GetMessageSizeFromImage gets the size of the message from the first four bytes encoded in the image

func MaxEncodeSize

func MaxEncodeSize(img image.Image) uint32

MaxEncodeSize given an image will find how many bytes can be stored in that image using least significant bit encoding ((width * height * 3) / 8 ) - 4 The result must be at least 4,

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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