
이미지의 LSB 스테가노그래피를 위한 의존성 없는 Go 라이브러리: 임의의 파일을 PNG 캐리어에 인코딩하고 숨겨진 메시지를 디코딩하며, 메시지 크기 사전 검사를 제공합니다.
스테가노그래피는 이미지에 간단한 LSB 스테가노그래피를 적용할 수 있도록 순수 Go로 작성된 라이브러리입니다. 이미지를 인코딩하고 디코딩하는 기능을 모두 갖추고 있습니다. 모든 형식의 파일을 저장할 수 있습니다. 이 라이브러리는 동일한 목적의 명령줄 유틸리티인 EthanWelsh의 Stego에서 영감을 받았습니다.
go get -u github.com/auyer/steganography
| 원본 | 인코딩됨 |
|---|---|
![]() | ![]() |
두 번째 이미지에는 Wikipedia의 스테고사우루스 설명 첫 단락이 포함되어 있으며, 예시로 examples/message.txt에서도 확인할 수 있습니다.
package main
import (
"bufio"
"image/png"
"io/ioutil"
"github.com/auyer/steganography"
)
쓰기 모드는 메시지를 받아 LSB 스테가노그래피를 사용하여 이미지 파일에 삽입함으로써, 메시지를 담은 비밀 이미지 파일을 생성하는 데 사용됩니다.
최소 이미지 크기는 1바이트당 24픽셀입니다. 추가 바이트마다 3픽셀이 더 필요합니다.
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()
참고: 간결함을 위해 모든 오류 검사를 제거했지만, 실제로는 포함해야 합니다.
길이 모드는 캐리어 이미지에 대해 사전 검사를 수행하여 얼마나 큰 파일을 저장할 수 있는지 추론하는 데 사용할 수 있습니다.
sizeOfMessage := steganography.GetMessageSizeFromImage(img) // retrieves the size of the encoded message
읽기 모드는 LSB 스테가노그래피를 사용하여 인코딩된 이미지를 읽고, 해당 이미지에서 숨겨진 메시지를 추출하는 데 사용됩니다.
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))
참고: 간결함을 위해 모든 오류 검사를 제거했지만, 실제로는 포함해야 합니다.
전체 예제는 examples/stego.go 파일을 참조하세요. 이 저장소의 원래 포크를 기반으로 한 명령줄 앱이지만, 스테가노그래피 라이브러리를 사용하도록 수정되었습니다.