Pure Golang Library that allows simple LSB steganography on images

Steganography Lib

GoDoc Go Report Card LICENSE MIT CircleCI 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 paragaph 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 minnimum 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 modifid to use the Steganography library.


Attributions

Owner
Rafael Passos
Software Engineer keybase.io/auyer
Rafael Passos
Comments
  • Example doesen't work

    Example doesen't work

    The example provided does encode the file but it does not decode it. Also, it does not include the correct "github.com/auyer/steganography" must be replaced with "gopkg.in/auyer/steganography.v2"

  • Does it work with jpg?

    Does it work with jpg?

    I'm using this library to encode some secrets into the image, but I'm not sure if it works with jpg.

    The example has a jpg image, but maybe it's only during decoding.

  • Following readme decode example gives errors in imageToRGBA

    Following readme decode example gives errors in imageToRGBA

    From this file (near copied from readme) https://github.com/scottleedavis/mattermost-plugin-watermark/blob/master/decode.go

    func main() {
    	inFile, _ := os.Open("./assets/test.jpg") // opening file
    	inFile.Close()
    
    	reader := bufio.NewReader(inFile) // buffer reader
    	img, _, _ := image.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))
    }
    

    gives the following error when run

    $ go run decode.go 
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x10b01e7]
    
    goroutine 1 [running]:
    gopkg.in/auyer/steganography%2ev2.imageToRGBA(0x0, 0x0, 0x0)
            /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:339 +0x37
    gopkg.in/auyer/steganography%2ev2.decode(0x400000000, 0x0, 0x0, 0x10c3080, 0x1, 0xc0000a8000)
            /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:202 +0x35
    gopkg.in/auyer/steganography%2ev2.GetMessageSizeFromImage(0x0, 0x0, 0x0)
            /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:237 +0x48
    main.main()
            /Users/scottd/workspace/mattermost-plugin-watermark/decode.go:20 +0x195
    exit status 2
    
  • Encode & decode in same memory/execution produce empty message output

    Encode & decode in same memory/execution produce empty message output

    During troubleshooting a failing test where this library is called by a plugin: https://github.com/scottleedavis/mattermost-plugin-watermark/blob/master/server/plugin_test.go#L69-L78 I found what appears to be a bug where calling Encode & Decode during the same memory/execution of a program, produces an empty message. However, when an encode happens separately from a decode, everything seems to work as intended. (In my case running Encode via plugin inside mattermost, and later downloading the image and running Decode)

    Two examples that fail on my system.

    • in memory https://gist.github.com/scottleedavis/25f5e7d1b97dcb8964b74712cfbc6a29
    • in files https://gist.github.com/scottleedavis/cf07abde16e15d7abde990282869471a Both examples above fail to set the message.

    If there any glaring errors in any of the above code, please let me know!

    Thank you for building this library! 👍

  • Missing go.sum

    Missing go.sum

    It appears this package is using the now recommended go modules, but has failed to include the go.sum file which is recommended to be checked into version control.

    From https://github.com/golang/go/wiki/Modules#releasing-modules-all-versions:

    Ensure your go.sum file is committed along with your go.mod file. See FAQ below for more details and rationale.

    Just bringing this to attention.

Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket

Features Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket Environment Variables IMAGE_SIZES - formax 200x20

Feb 2, 2022
A go library for reading and creating ISO9660 images

iso9660 A package for reading and creating ISO9660, forked from https://github.com/kdomanski/iso9660. Requires Go 1.13 or newer. Joliet and Rock Ridge

Mar 4, 2021
A pure Go 3D math library.

MathGL This is a Go matrix and vector math library specialized for Open GL graphics capabilities. This package is made primarily with code generation

Dec 24, 2022
Simple ANSi to PNG converter written in pure Go

AnsiGo Description AnsiGo is a simple ANSi to PNG converter written in pure Go. It converts files containing ANSi sequences (.ANS) into PNG images. Fo

May 17, 2022
Go-Generative-Art-A - Generate PNG art from source images! GOLang Generative Art
Go-Generative-Art-A - Generate PNG art from source images! GOLang Generative Art

GO Lang Generative Art Tool A Take source images and generate art utilizing sour

Nov 21, 2022
Pure golang image resizing
Pure golang image resizing

This package is no longer being updated! Please look for alternatives if that bothers you. Resize Image resizing for the Go programming language with

Jan 9, 2023
NanoVGo NanoVGNanoVGo is pure golang implementation of NanoVG. The same author maintains the NanoGUI.go project mentioned above.

NanoVGo Pure golang implementation of NanoVG. NanoVG is a vector graphics engine inspired by HTML5 Canvas API. DEMO API Reference See GoDoc Porting Me

Dec 6, 2022
Read and write Netpbm images from Go programs

netpbm Introduction netpbm is a package for the Go programming language that implements image decoders and encoders for the Netpbm image formats. The

Dec 29, 2022
Resize images and animated GIFs in Go

Lilliput relies on mature, high-performance C libraries to do most of the work of decompressing, resizing and compressing images. It aims to do as little memory allocation as possible and especially not to create garbage in Go. As a result, it is suitable for very high throughput image resizing services.

Jan 3, 2023
Reproducing images with geometric primitives.
Reproducing images with geometric primitives.

Primitive Pictures Reproducing images with geometric primitives. How it Works A target image is provided as input. The algorithm tries to find the sin

Dec 31, 2022
Fast and secure standalone server for resizing and converting remote images

imgproxy imgproxy is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, sp

Jan 1, 2023
An iterative algorithm to generate high quality triangulated images.
An iterative algorithm to generate high quality triangulated images.

Triangula uses a modified genetic algorithm to triangulate images. It works best with images smaller than 3000px and with fewer than 3000 points, typically producing an optimal result within a couple of minutes.

Jan 8, 2023
Generate high-quality triangulated art from images.
Generate high-quality triangulated art from images.

An iterative algorithm to generate high quality triangulated images.

May 26, 2021
A cross-platform tool to convert images into ascii art and print them on the console
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Dec 30, 2022
Convert images to computer generated art using delaunay triangulation.
Convert images to computer generated art using delaunay triangulation.

▲ Triangle is a tool for generating triangulated image using delaunay triangulation. It takes a source image and converts it to an abstract image comp

Dec 29, 2022
Emoji images for Ebiten
Emoji images for Ebiten

Ebiten Emoji Alpha version: The API is not stable yet Package emoji provides Emoji images for Ebiten. Usage func (*YourGame) Draw(screen *ebiten.Image

Dec 11, 2022
An experiment in rendering images with Slack custom emojis.
An experiment in rendering images with Slack custom emojis.

emojimage An experiment in rendering images with Slack custom emojis. Example Usage 1. Initializing your workspace First, you'll need to upload 1,332

Mar 12, 2022
a tool to output images as RGB ANSI graphics on the terminal
a tool to output images as RGB ANSI graphics on the terminal

imgcat Tool to output images in the terminal. Built with bubbletea install homebrew brew install trashhalo/homebrew-brews/imgcat prebuilt packages Pr

Dec 28, 2022
Image compression codec for 16 bit medical images

MIC - Medical Image Codec This library introduces a lossless medical image compression codec MIC for 16 bit images which provides compression ratio si

Dec 26, 2021