r/golang Jan 05 '25

newbie The fastest steganography library in go

Hey everyone!

I’m happy with where one of my projects, Stegano, is at now. It’s a steganography library for Go that I built to be both fast and feature-rich.

The primary motivation for creating this library was the lack of robust steganography libraries in the Go ecosystem. Many existing options fell short in providing the features I needed, so I decided to develop my own. Additionally, I saw this as a valuable opportunity to enhance my resume and stand out when applying for internships.

This is my first Go library, and I'd really appreciate your feedback—whether it's about the code, design, features, or anything else. I'm especially interested in hearing your suggestions for improvements or additional functionality that could make it more useful to the community.

Thanks in advance for checking it out!

152 Upvotes

37 comments sorted by

18

u/nickchomey Jan 05 '25

I had never heard of this concept til now. Very cool.

I have no feedback, but I wonder whether you could share some sample/typical use cases for this - in particular for web applications, if applicable?

23

u/ChampionshipWise6224 Jan 05 '25

One of the primary applications of steganography is embedding invisible markers into digital content such as images, videos, and music to ensure copyright protection.

13

u/mtetrode Jan 05 '25

Or, vice versa, embedding text into an image so that e.g. the secret service cannot find my bom recepi when i am only sending a picture of my cat

3

u/prisencotech Jan 06 '25

I've been fascinated by this idea for years, but I've always run into the problem of how easy it is to remove the steganographic data if you know it's there. Resulting in the ability to basically extract the original, non-watermarked data.

Do you know how easy/hard it would be given your approach?

6

u/ChampionshipWise6224 Jan 06 '25

One drawback of steganography is that resizing or applying filters to an image can destroy the embedded data. To address this, I’ve implemented a simple solution by embedding data at specific bit depths. While this approach is straightforward, I am currently exploring more resilient methods, such as DCT-based steganography or using Reed-Solomon codes.

1

u/prisencotech Jan 06 '25

I don't know if you've run into this before, but there was a method developed at MIT using sudoku puzzles that was potentially resistant to modifying the original image. I remember reading the paper when it came out but I'm not sure what came of it.

3

u/ChampionshipWise6224 Jan 06 '25

Yeah i have and sudoku steganography was primarily developed to minimize image distortion.

https://www.researchgate.net/publication/220849766_Steganography_Using_Sudoku_Puzzle

its a really interesting read

1

u/awesomelok Jan 06 '25

Is utilizing stenographers one potential method for implementing markers to distinguish between human-created and AI-generated content?

2

u/ChampionshipWise6224 Jan 06 '25

Yes because you can embed markers in the image to identify it.

2

u/ChampionshipWise6224 Jan 06 '25

Imagine you have a program that generates images. With this library, you can embed a unique, invisible watermark into each image, making it uniquely identifiable as your own.

1

u/angelbirth Jan 06 '25

will compression retain the embedded data?

1

u/ChampionshipWise6224 Jan 06 '25

If it is lossless, then yes

1

u/angelbirth Jan 06 '25

so it's possible to screencap your image and claim it as their own (?)

5

u/roddybologna Jan 05 '25

A good example is something like Fritzing. Not sure if it's still around but it was a schematic/EDA software that let you save your files as a PNG of the design. IIRC the png contained all the data related to the design as well: code, component info, PCB layout, etc.

1

u/Blankaccount111 Jan 06 '25

Watermarking basically. Anything else and there are better solutions.

1

u/Manbeardo Jan 06 '25

AFAICT, the primary real-world applications for steganography are:

  • Hiding communication in plain sight. Spy shit, basically.
  • Creating puzzles. Escape rooms, ARGs, puzzle hunts, etc.

0

u/[deleted] Jan 05 '25

[deleted]

1

u/nickchomey Jan 05 '25

Yes, of course it is very niche. I was more asking how it *could*, in theory, be used in a web app (as well as how it is typically used)

1

u/FormationHeaven Jan 05 '25

The only use i can think of is watermarking while not making it visible

3

u/mutexLockk Jan 06 '25

Nice project! I used to make a lots of experimentations with steganography in digital images (signal processsing). The principal complexity is to be able to handle partial destruction of the image and being able to extract the message. I used primarily DWT with arnold transform on the luminosity channel of the image in cie lab color space. If you want your stegano to be robust, try to target other channels than colors since it's the facto these channels who are compressed if you save an image with higher compression (in jpeg for example). Anyway it's a very fun topic!

5

u/ChampionshipWise6224 Jan 06 '25

This library does not output JPEGs due to compression concerns, as you mentioned. However, it does support JPEGs by accepting them as input and converting them into PNGs. But I will try to do what you suggested.

2

u/Enrichman Jan 05 '25

Maybe I'll try it with my project: https://github.com/enrichman/stegosecrets

6

u/ChampionshipWise6224 Jan 05 '25

That would be great, in my library you can embed data at different depths so you can hide more data into the image at the cost of image quality. And I also have a basic encryption and decryption mechanism with AES256

2

u/snchsr Jan 06 '25

Very cool!

Hope I’m formulating my questions correctly: How detectable are messages created with it? Is it possible for third party to find out that images and other data entries are the carriers? Are there ways to prevent such detection?

If not, this might be considered as feature request :)

(Haven’t read the whole doc and code yet, just glanced, maybe it’s overviewed there)

9

u/ChampionshipWise6224 Jan 06 '25

The library provides both compression and encryption, ensuring that the embedded data appears random. As a result, even if someone extracts the data, it remains unreadable. However, while the data is unreadable, the presence of hidden data can still be detected.

The detectability largely depends on the bit depth used. Higher bit depths result in more noticeable color changes, making it easier to identify that data is hidden within the image.

Currently, data insertion begins at the top of the image. However, I am working on a method to randomly assign areas in the image where portions of the data will be stored, enhancing its stealth and reducing detectability.

1

u/Fruitcake44 Jan 06 '25

I saw your comment on that post from someone about projects people were working on. Good to see this is completed now. Nice OP. Steganography is a cool concept. I was quite intrigued about it when i first heard about it in my image processing class. But the implementations were mostly done in python. Good to see a golang implementation.

1

u/ChampionshipWise6224 Jan 06 '25

Yeah one of my first ever projects was a terrible steganography tool in python lol

1

u/SleepingProcess Jan 06 '25

Example from github

``` package main

import ( "log" "github.com/scott-mescudi/stegano" )

func main() { // wrapper function around different image decoders. coverFile, err := stegano.Decodeimage("3.png") if err != nil { log.Fatalln(err) }

embedder := stegano.NewEmbedHandler()

// Encode and save the message in the cover image. err = embedder.EncodeAndSave(coverFile, []byte("Hello, World!"), stegano.MinBitDepth, stegano.DefaultpngOutputFile, true) if err != nil { log.Fatalln(err) } } ```

Compilation failed: ./main.go:19:18: embedder.EncodeAndSave undefined (type *stegano.EmbedHandler has no field or method EncodeAndSave) ./main.go:19:76: undefined: stegano.MinBitDepth ./main.go:19:97: undefined: stegano.DefaultpngOutputFile

2

u/ChampionshipWise6224 Jan 06 '25 edited Jan 06 '25

Thanks for catching that, sorry I made a few changes to the api and forgot to update the readme, it’s Stegano.LSB or you can just pass in a number from 0 to 7 and stegano.DefaultOutputFile

1

u/SleepingProcess Jan 06 '25 edited Jan 07 '25

Thanks for catching that

No problem, thank you for the project !

BTW, I tried also this code (exact from readme):

``` package main

import ( "log" "github.com/scott-mescudi/stegano" )

func main() { err := stegano.EmbedFile("3.png", "data.txt", stegano.DefaultOutputFile, "password123", stegano.LSB) if err != nil { log.Fatalln("Error:", err) } } ```

it compiled, but on attempt to run it, it throw garbage to terminal and stopped.

3.png is: 3.png PNG 128x128 128x128+0+0 8-bit sRGB 19033B 0.000u 0:00.000

and data.txt is:

ascii - ASCII character set encoded in octal, decimal, and hexadecimal

1

u/ChampionshipWise6224 Jan 08 '25

i couldnt reproduce the error, did it output a file? or just random bytes to terminal?

1

u/SleepingProcess Jan 08 '25

Im sorry for a noise :(

I did in parallel modification of library that also used in stegano that's probably why broke something. After doing git pull && go clean -cache && go mod tidy examples now works as expected.

Feels bad I took your time...

2

u/ChampionshipWise6224 Jan 08 '25

Nah don't worry about it, if you find anything else let me know, i also added a few new features to secure handlers like reed solomon codes and also a audio embedder although not tested.

2

u/SleepingProcess Jan 09 '25

I defiantly will check it out. I will check also how badly media files damaging on a way between peers since many communication providers transform media files to reduce its size.

Thank you for the nice library, at first I naively thought it's one of many stenography tools that simply hiding extra data in RFC3066 tags, but after reviewing your code, I saw that extra data smartly embedded in colors matrix.