Skip to content

Instantly share code, notes, and snippets.

@scottleedavis
Last active September 7, 2019 22:19
Show Gist options
  • Save scottleedavis/cf07abde16e15d7abde990282869471a to your computer and use it in GitHub Desktop.
Save scottleedavis/cf07abde16e15d7abde990282869471a to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"bytes"
"fmt"
"gopkg.in/auyer/steganography.v2"
"image"
"os"
)
func main() {
inFile, err := os.Open("./assets/pre_test.png") // opening file
if err != nil {
fmt.Println("unable to open file")
}
defer inFile.Close()
reader := bufio.NewReader(inFile) // buffer reader
img, _, err := image.Decode(reader)
if err != nil {
fmt.Println("ERROR: original image is corrupt " + err.Error())
return
}
w := &bytes.Buffer{}
err = steganography.Encode(w, img, []byte("this is a watermark"))
if err != nil {
fmt.Println(err.Error())
}
//Save file
outFile, err := os.Create("test.png") // Creates file to write the message into
if err != nil {
fmt.Println("Error creating file %s: %v", "test.png", err)
}
w.WriteTo(outFile) // this is more concise
outFile.Close()
//Read file
inFile2, err := os.Open("test.png")
if err != nil {
fmt.Println("unable to open file")
}
defer inFile2.Close()
reader = bufio.NewReader(inFile2)
img, _, err = image.Decode(reader)
if err != nil {
fmt.Println("unable to decode file")
}
sizeOfMessage := steganography.GetMessageSizeFromImage(img)
msg := steganography.Decode(sizeOfMessage, img)
fmt.Println("**** " + string(msg))
}
@scottleedavis
Copy link
Author

updated with new png, and it works. must be the original png corrupted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment