Class ByteArrayImgEncloser

java.lang.Object
de.das.encrypter.tools.ByteArrayEncloser
de.das.encrypter.tools.ByteArrayImgEncloser

public class ByteArrayImgEncloser extends ByteArrayEncloser
Byte array image enclosers interweave the bits of the individual bytes of a byte array with the bytes of the image data of an image in PNG format. The changes to the image content are so minor that they are not visible to the naked eye. Enclosed can be the bytes of a simple byte array or the bytes of a file. The difference is that for the bytes of a file an additional identifier with the original file name is attached. The bits of the data to be hidden are hidden in the least significant bits of the color components of the pixels.
  • Field Summary

    Fields inherited from class de.das.encrypter.tools.ByteArrayEncloser

    HIDDEN_FILE_ID, ID
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    assemble(BufferedImage img, int count)
    Uses the LSB bits of the R,G, and B components of the pixels of the given image to reconstruct the desired number of data bytes of a byte array using the bits to fill the respective bytes from MSB to LSB as the pixels are scanned in the horizontal before vertical direction.
    byte[]
    assemble(BufferedImage img, int count, boolean progress)
    Uses the LSB bits of the R,G, and B components of the pixels of the given image to reconstruct the desired number of data bytes of a byte array using the bits to fill the respective bytes from MSB to LSB as the pixels are scanned in the horizontal before vertical direction.
    void
    Set a flag that indicates to interrupt a running process immediately.
    boolean
    canHold(int length, BufferedImage img)
    Checks if the capacity of the given image is sufficient to hold the given number of bytes.
    boolean
    canHold(int length, File f)
    Checks if the capacity of the image in the given file is sufficient to hold the given number of bytes.
    void
    Erases the identifier for hidden data.
    boolean
    Regains a possible header from the image bits and checks, whether they contain the required ID.
    boolean
    Assumes the given file contains an image in PNG format and checks, if there is any woven data.
    boolean
    Assumes the given file contains an image in PNG format and checks, if there is any woven data and these data are from a file.
    int
    Calculates the maximum acquisition capacity of a given image under the condition that each color component (R, G and B) provides the LSB bit for the bits of the data to be woven in.
    byte[]
    getContainedBytes(File f, int count)
    Reconstructs the desired number of data bytes of a byte array from the image contained in the given file.
    int
    Get the amount of bytes hidden in the given file.
    Extracts the file name of the hidden file from the image in the given file.
    void
    hideData(byte[] d, BufferedImage img)
    Weaves the given data into the given image.
    void
    hideData(byte[] data, File f)
    Weaves the given data into the given image.
    byte[]
    Restores the data hidden in the image.
    byte[]
    Restores the data hidden in the image contained in the given file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteArrayImgEncloser

      public ByteArrayImgEncloser()
    • ByteArrayImgEncloser

      public ByteArrayImgEncloser(ProgressListener pl)
  • Method Details

    • canHold

      public boolean canHold(int length, File f) throws IOException
      Checks if the capacity of the image in the given file is sufficient to hold the given number of bytes.
      Parameters:
      length - the length in bytes of a file.
      f - the file representing the image to be used as the container.
      Returns:
      true, if the container is able to hold the data.
      Throws:
      IOException - if the image cannot be opened.
    • canHold

      public boolean canHold(int length, BufferedImage img)
      Checks if the capacity of the given image is sufficient to hold the given number of bytes.
      Parameters:
      length - the length in bytes of a file.
      img - the image to be used as the container.
      Returns:
      true, if the container is able to hold the data.
    • getCapacity

      public int getCapacity(BufferedImage img)
      Calculates the maximum acquisition capacity of a given image under the condition that each color component (R, G and B) provides the LSB bit for the bits of the data to be woven in.
      Parameters:
      img - the image to be used as the container.
      Returns:
      the maximum acquisition capacity of the given image.
    • hideData

      public void hideData(byte[] d, BufferedImage img) throws Exception
      Weaves the given data into the given image.
      Parameters:
      d - a given byte array.
      img - a given image.
      Throws:
      Exception - when the specified image is not able to capture the given data.
    • assemble

      public byte[] assemble(BufferedImage img, int count) throws Exception
      Uses the LSB bits of the R,G, and B components of the pixels of the given image to reconstruct the desired number of data bytes of a byte array using the bits to fill the respective bytes from MSB to LSB as the pixels are scanned in the horizontal before vertical direction.
      Parameters:
      img - a given image.
      count - the number of bytes to be reconstructed.
      Returns:
      a byte array of length "count" with the reconstructed data.
      Throws:
      Exception - in case of any error.
    • assemble

      public byte[] assemble(BufferedImage img, int count, boolean progress) throws Exception
      Uses the LSB bits of the R,G, and B components of the pixels of the given image to reconstruct the desired number of data bytes of a byte array using the bits to fill the respective bytes from MSB to LSB as the pixels are scanned in the horizontal before vertical direction.
      Parameters:
      img - a given image.
      count - the number of bytes to be reconstructed.
      progress - a flag indicating that the current amount should be communicated to the listener.
      Returns:
      a byte array of length "count" with the reconstructed data.
      Throws:
      Exception - in case of any error.
    • containsHiddenData

      public boolean containsHiddenData(File f) throws IOException, Exception
      Assumes the given file contains an image in PNG format and checks, if there is any woven data.
      Parameters:
      f - a given file.
      Returns:
      true if the file contains hidden data.
      Throws:
      IOException - if any problems with the given file.
      Exception - in any other error cases.
    • containsHiddenFile

      public boolean containsHiddenFile(File f) throws Exception
      Assumes the given file contains an image in PNG format and checks, if there is any woven data and these data are from a file.
      Parameters:
      f - a given file.
      Returns:
      true if the file contains a hidden file.
      Throws:
      Exception - in case of any error.
    • hideData

      public void hideData(byte[] data, File f) throws Exception
      Weaves the given data into the given image.
      Parameters:
      data - the data to be woven into the image of the specified file.
      f - a file in PNG format representing an image.
      Throws:
      Exception - in case of any error.
    • containsHiddenData

      public boolean containsHiddenData(BufferedImage img) throws Exception
      Regains a possible header from the image bits and checks, whether they contain the required ID.
      Parameters:
      img - the image to be tested for hidden data.
      Returns:
      true, if the image contains hidden data.
      Throws:
      Exception - in case of any error.
    • regainData

      public byte[] regainData(File f) throws IOException, Exception
      Restores the data hidden in the image contained in the given file.
      Parameters:
      f - a file containing an image in PNG format with hidden data.
      Returns:
      the recovered data.
      Throws:
      IOException - in case of problems with file and image.
      Exception - in case of other errors.
    • regainData

      public byte[] regainData(BufferedImage img) throws Exception
      Restores the data hidden in the image.
      Parameters:
      img - the image containing hidden data.
      Returns:
      the recovered data.
      Throws:
      Exception - in case of any error.
    • getHiddenArraySize

      public int getHiddenArraySize(File f) throws Exception
      Get the amount of bytes hidden in the given file.
      Parameters:
      f - a given file.
      Returns:
      the number of bytes hidden in the given file.
      Throws:
      Exception - in case of any error.
    • clear

      public void clear(File f) throws IOException
      Erases the identifier for hidden data.
      Parameters:
      f - a given file containing an image.
      Throws:
      IOException - in case of problems with the image.
    • breakIt

      public void breakIt()
      Set a flag that indicates to interrupt a running process immediately.
    • getHiddenFileName

      public String getHiddenFileName(File f) throws IOException, Exception
      Extracts the file name of the hidden file from the image in the given file. It is assumed that it was previously checked whether the image contains a hidden file.
      Parameters:
      f - a given file.
      Returns:
      the file name of the hidden file.
      Throws:
      IOException - in case of issues with the image.
      Exception - in all other cases.
    • getContainedBytes

      public byte[] getContainedBytes(File f, int count) throws IOException, Exception
      Reconstructs the desired number of data bytes of a byte array from the image contained in the given file. This method should be used only if it is sure that the hidden data is a file content and not just a byte array.
      Parameters:
      f - a file containing a PNG image.
      count - the number of hidden bytes to be recovered.
      Returns:
      a byte array with the recovered data.
      Throws:
      IOException - in case of issues with the image.
      Exception - in all other cases.