stego / glue.go

package stego

import (
	"crypto/aes"
)

// Interface for arbitrary steganography implementation.
type BitHider interface {
	// How many bytes is this medium capable of storing?
	ByteCapacity() int
	// Hide these bytes (must be under the capacity) into the medium.
	// Unused bytes on the end will be randomly padded.
	Embed([]byte) error
	// Extract the full capacity of bytes, including padding.
	Reveal() ([]byte, error)
}

// Hide the data encrypted with the key (a valid AES key, 16 or so bytes).
// An empty key hides the data unencrypted.
func HideData(bh BitHider, data, key []byte) error {
	var stream []byte
	if len(key) == 0 {
		stream = EncodeStream(data)
	} else {
		c, err := aes.NewCipher(key)
		if err != nil {
			return err
		}
		stream = CryptoEncodeStream(data, c)
	}
	return bh.Embed(stream)
}

// Retrieve data hidden here under this key, if any.
// An empty key looks without any encryption.
func FindData(bh BitHider, key []byte) ([]byte, error) {
	stream, err := bh.Reveal()
	if err != nil {
		return nil, err
	}
	if len(key) == 0 {
		return DecodeStream(stream)
	}
	c, err := aes.NewCipher(key)
	if err != nil {
		return nil, err
	}
	return CryptoDecodeStream(stream, c)
}

// Hide the data encrypted with this passphrase
func PassphraseHideData(bh BitHider, data, passphrase []byte) error {
	stream := PassphraseEncodeStream(data, passphrase)
	return bh.Embed(stream)
}

// Retrieve data hidden here under this passphrase, if any.
func PassphraseFindData(bh BitHider, passphrase []byte) ([]byte, error) {
	stream, err := bh.Reveal()
	if err != nil {
		return nil, err
	}
	return PassphraseDecodeStream(stream, passphrase)
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.