Skip to content

Instantly share code, notes, and snippets.

@buroz
Created June 10, 2020 13:11
Show Gist options
  • Save buroz/2cefa591950e79c4865f30f8a6ff3829 to your computer and use it in GitHub Desktop.
Save buroz/2cefa591950e79c4865f30f8a6ff3829 to your computer and use it in GitHub Desktop.
Steganography in Golang
package main
import (
"bufio"
"bytes"
"fmt"
"image/jpeg"
"image/png"
"log"
"os"
"github.com/auyer/steganography"
)
func Encode() {
inFile, _ := os.Open("/home/buroz/Pictures/95e46aa5-0849-4fec-83f6-0049926eb5d9.jpeg") // opening file
reader := bufio.NewReader(inFile) // buffer reader
img, _ := jpeg.Decode(reader) // decoding to golang's image.Image
w := new(bytes.Buffer) // buffer that will recieve the results
err := steganography.Encode(w, img, []byte("This is a secret message!")) // Encode the message into the image
if err != nil {
log.Printf("Error Encoding file %v", err)
return
}
outFile, _ := os.Create("out_file.jpeg") // create file
w.WriteTo(outFile) // write buffer to it
outFile.Close()
}
func main() {
inFile, _ := os.Open("./out_file.jpeg") // 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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment