Class ImageSteg
- java.lang.Object
-
- steganography.image.ImageSteg
-
- All Implemented Interfaces:
Steganography
public class ImageSteg extends java.lang.Object implements Steganography
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_SEED
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
decode(byte[] steganographicData)
Decodes a hidden message in the given steganographicData (an image) and returns it as a byte array.byte[]
decode(byte[] steganographicData, long seed)
Decodes a hidden message in the given steganographicData (an image) and returns it as a byte array.byte[]
decodeRaw(int length, byte[] steganographicData)
Interprets an amount of (length * 8) pixels as a hidden message and returns it as a byte array.byte[]
decodeRaw(int length, byte[] steganographicData, long seed)
Interprets an amount of (length * 8) pixels as a hidden message and returns it as a byte array.byte[]
encode(byte[] carrier, byte[] payload)
Encodes the given payload in the given carrier (image, mp3, ...) and returns the result.byte[]
encode(byte[] carrier, byte[] payload, long seed)
Encodes the given payload in the given carrier (image, mp3, ...) and returns the result.int
getImageCapacity(byte[] image)
Returns the maximum number of bytes that can be encoded (as payload) in the given image.boolean
isSteganographicData(byte[] data)
Tests whether the given data has a hidden message encoded in it.boolean
isSteganographicData(byte[] data, long seed)
Tests whether the given data has a hidden message encoded in it.
-
-
-
Field Detail
-
DEFAULT_SEED
public static final long DEFAULT_SEED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ImageSteg
public ImageSteg()
Creates a new ImageSteg with settings:
- useDefaultHeader = true
- useTransparent = false
This means, a default header will be encoded in the image to simplify decoding and fully transparent pixels will not be used for encoding or decoding.
This is equivalent to ImageSteg(true, false).
- See Also:
ImageSteg(boolean, boolean)
-
ImageSteg
public ImageSteg(boolean useDefaultHeader, boolean useTransparent)
Creates a new ImageSteg with the given settings.
useDefaultHeader- if true, the default header will be encoded in the image. The hidden message can then be decoded using ImageSteg.decode(...).
- if false, no header will be encoded in the image. The hidden message can only be decoded using ImageSteg.decodeRaw(length, ...)
- if true, fully transparent pixels will be used for encoding and decoding
- if false, fully transparent pixels will not be used for encoding and decoding
- This value must be equal while encoding and decoding to successfully decode the hidden message.
- This value can only affect PNGs that contain fully transparent pixels.
- If an image has no fully transparent pixels, this value will be ignored.
- If the image is a GIF, this value will be ignored.
- BMPs with transparent pixels are not supported by this class.
- Parameters:
useDefaultHeader
- should the default header be used for encoding?useTransparent
- should fully transparent pixels be used for encoding and decoding?- See Also:
decode(byte[])
,decode(byte[], long)
,decodeRaw(int, byte[])
,decodeRaw(int, byte[], long)
-
-
Method Detail
-
encode
public byte[] encode(byte[] carrier, byte[] payload) throws java.io.IOException, UnsupportedImageTypeException, NoImageException, ImageWritingException, ImageCapacityException
Description copied from interface:Steganography
Encodes the given payload in the given carrier (image, mp3, ...) and returns the result. The format of the returned media will be the same as carrier. Carrier needs to be an exact media representation as it would be read from a file by an InputStream.- Specified by:
encode
in interfaceSteganography
- Parameters:
carrier
- media used to hide the payloadpayload
- data to hide- Returns:
- steganographic data - exact media representation. Can be stored as it is to a file to open externally
- Throws:
java.io.IOException
- if a problem occurs during reading of carrier or payloadUnsupportedImageTypeException
NoImageException
ImageWritingException
ImageCapacityException
-
encode
public byte[] encode(byte[] carrier, byte[] payload, long seed) throws java.io.IOException, NoImageException, UnsupportedImageTypeException, ImageWritingException, ImageCapacityException
Description copied from interface:Steganography
Encodes the given payload in the given carrier (image, mp3, ...) and returns the result. The format of the returned media will be the same as carrier. Carrier needs to be an exact media representation as it would be read from a file by an InputStream.
The Seed changes the way the payload is encoded. When decoding the result, the exact same Seed needs to be given to decode()
- Specified by:
encode
in interfaceSteganography
- Parameters:
carrier
- media used to hide the payloadpayload
- data to hideseed
- affects the resulting steganographic data (similar to a password)- Returns:
- steganographic data - exact media representation. Can be stored as it is to a file to open externally
- Throws:
java.io.IOException
- if a problem occurs during reading of carrier or payloadNoImageException
UnsupportedImageTypeException
ImageWritingException
ImageCapacityException
-
decode
public byte[] decode(byte[] steganographicData) throws java.io.IOException, UnsupportedImageTypeException, NoImageException, UnknownStegFormatException
Decodes a hidden message in the given steganographicData (an image) and returns it as a byte array.
This method will fail, if the message was hidden without using the default header. Use ImageSteg.decodeRaw() for this purpose.
Reasons for failing with an UnknownStegFormatExceptions are:
- there is no hidden message
- the message was hidden with 'useDefaultHeader = false'
- the value for 'useTransparent' was different when hiding the message
- the message was hidden using an unknown algorithm
- Specified by:
decode
in interfaceSteganography
- Parameters:
steganographicData
- Image containing the hidden message to decode- Returns:
- the hidden message as a byte array
- Throws:
java.io.IOException
- if an error occurs during reading 'steganographicData'NoImageException
- if no image could be read from 'steganographicData'UnsupportedImageTypeException
- if the type of the given image is not supportedUnknownStegFormatException
- if the default header could not be found- See Also:
decodeRaw(int, byte[])
-
decode
public byte[] decode(byte[] steganographicData, long seed) throws java.io.IOException, NoImageException, UnsupportedImageTypeException, UnknownStegFormatException
Decodes a hidden message in the given steganographicData (an image) and returns it as a byte array.
This method will fail, if the message was hidden without using the default header. Use ImageSteg.decodeRaw() for this purpose.
Reasons for failing with an UnknownStegFormatExceptions are:
- there is no hidden message
- the message was hidden with 'useDefaultHeader = false'
- the value for 'useTransparent' was different when hiding the message
- the message was hidden using an unknown algorithm
- Specified by:
decode
in interfaceSteganography
- Parameters:
steganographicData
- Image containing the hidden message to decodeseed
- seed that was used to encode the given stenographicData- Returns:
- the hidden message as a byte array
- Throws:
java.io.IOException
- if an error occurs during reading 'steganographicData'NoImageException
- if no image could be read from 'steganographicData'UnsupportedImageTypeException
- if the type of the given image is not supportedUnknownStegFormatException
- if the default header could not be found- See Also:
decodeRaw(int, byte[], long)
-
decodeRaw
public byte[] decodeRaw(int length, byte[] steganographicData) throws java.io.IOException, NoImageException, UnsupportedImageTypeException
Interprets an amount of (length * 8) pixels as a hidden message and returns it as a byte array.
This method will not search for a header or validate the retrieved data in any form. If 'steganographicData' contains a supported image, this method will always return a result. Whether this result is the hidden message, depends on the settings used:
- 'useTransparent' during encoding == 'useTransparent' during decoding
- 'payload.length' during encoding == 'length' during decoding
- No seed used during encoding (thereby using ImageSteg.DEFAULT_SEED)
- 'useDefaultHeader' == false during encoding
- Parameters:
length
- Length (in bytes) of the hidden messagesteganographicData
- Data containing data to extract- Returns:
- a byte array of length == "length" as a result of decoding (length * 8) pixels
- Throws:
java.io.IOException
- if an error occurs during reading 'steganographicData'NoImageException
- if no image could be read from 'steganographicData'UnsupportedImageTypeException
- if the type of the given image is not supported
-
decodeRaw
public byte[] decodeRaw(int length, byte[] steganographicData, long seed) throws java.io.IOException, NoImageException, UnsupportedImageTypeException
Interprets an amount of (length * 8) pixels as a hidden message and returns it as a byte array.
This method will not search for a header or validate the retrieved data in any form. If 'steganographicData' contains a supported image, this method will always return a result. Whether this result is the hidden message, depends on the settings used:
- 'useTransparent' during encoding == 'useTransparent' during decoding
- 'payload.length' during encoding == 'length' during decoding
- 'seed' during encoding == 'seed' during decoding
- 'useDefaultHeader' == false during encoding
- Parameters:
length
- Length (in bytes) of the hidden messagesteganographicData
- Data containing data to extractseed
- seed that was used to encode the given stenographicData- Returns:
- a byte array of length == "length" as a result of decoding (length * 8) pixels
- Throws:
java.io.IOException
- if an error occurs during reading 'steganographicData'NoImageException
- if no image could be read from 'steganographicData'UnsupportedImageTypeException
- if the type of the given image is not supported
-
isSteganographicData
public boolean isSteganographicData(byte[] data) throws java.io.IOException, NoImageException, UnsupportedImageTypeException
Description copied from interface:Steganography
Tests whether the given data has a hidden message encoded in it. This method only works if the message was encoded using the given Seed or the respective default Seed. Otherwise it will always return false.
The use of this method is discouraged. It saves very little resources compared to decode(...). So unless you need to test a lot of possible steganographicData, just use decode(...) and catch the UnknownStegFormatException
- Specified by:
isSteganographicData
in interfaceSteganography
- Parameters:
data
- data to test- Returns:
- true if the given data has a hidden message encoded in it
- Throws:
java.io.IOException
- if a problem occurs during reading of dataNoImageException
UnsupportedImageTypeException
-
isSteganographicData
public boolean isSteganographicData(byte[] data, long seed) throws java.io.IOException, NoImageException, UnsupportedImageTypeException
Description copied from interface:Steganography
Tests whether the given data has a hidden message encoded in it. This method only works if the message was encoded using the given Seed. Otherwise it will always return false.
The use of this method is discouraged. It saves very little resources compared to decode(...). So unless you need to test a lot of possible steganographicData, just use decode(...) and catch the UnknownStegFormatException
- Specified by:
isSteganographicData
in interfaceSteganography
- Parameters:
data
- data to testseed
- seed the hidden message was encoded with- Returns:
- true if the given data has a hidden message encoded in it
- Throws:
java.io.IOException
- if a problem occurs during reading of dataNoImageException
UnsupportedImageTypeException
-
getImageCapacity
public int getImageCapacity(byte[] image) throws java.io.IOException, NoImageException, UnsupportedImageTypeException
Returns the maximum number of bytes that can be encoded (as payload) in the given image. This method accounts for the use of transparent pixels and default header as given to the constructor.- Parameters:
image
- image to potentially encode bytes in- Returns:
- the payload-capacity of image
- Throws:
java.io.IOException
- if an error occurs during reading the imageNoImageException
- if no image could be read from the imageUnsupportedImageTypeException
- if the type of the given image is not supported- See Also:
ImageSteg(boolean, boolean)
-
-