Package com.iizix.nio

Class DataPacket


  • public class DataPacket
    extends java.lang.Object
    This class implements the cryptographic interface for the client/server communication. The encryption algorithm is NOT intended for advanced encryption, rather to hide otherwise "visible" data such as user ID's and passwords.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataPacket()
      The default cryptographic interface only implements the most simple way of garbling the byte data.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] compress​(byte[] data, int length)
      Tries to compress the input data to a smaller chunk.
      static byte[] compress2​(byte[] data, int length)
      Always compresses the input data to perhaps a smaller chunk.
      static byte[] decompress​(byte[] data)
      Decompress the data.
      byte[] decrypt​(byte[] indata, int offset, int len)
      Decrypts the data.
      byte[] encrypt​(byte[] data, int length)
      Encrypts the data.
      • Methods inherited from class java.lang.Object

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

      • DataPacket

        public DataPacket()
        The default cryptographic interface only implements the most simple way of garbling the byte data.

        In this implementation, nothing needs to be done in the constructor.

    • Method Detail

      • encrypt

        public byte[] encrypt​(byte[] data,
                              int length)
        Encrypts the data. The decrypt method has to make sure that the same data that is input to the encrypt method is provided as a return to this method.

        Note: if any changes to the buffer is required and the buffer is of the same length, use the original buffer in order to spare the virtual machine of any memory freeing. In this case, the same buffer is returned as only the content have changed, not the size.

      • decrypt

        public byte[] decrypt​(byte[] indata,
                              int offset,
                              int len)
        Decrypts the data.
        Parameters:
        indata - Input data.
        offset - Offset in input data.
        len - Length of input data.
      • compress

        public static byte[] compress​(byte[] data,
                                      int length)
        Tries to compress the input data to a smaller chunk. If this chunk is not at least 5% smaller, the best thing is to use the data uncompressed and in this case the function will return null.
        Parameters:
        data - the input data to compress.
        Returns:
        the compressed data, or null if there is no need for compression.
      • compress2

        public static byte[] compress2​(byte[] data,
                                       int length)
        Always compresses the input data to perhaps a smaller chunk.
        Parameters:
        data - the input data to compress.
        Returns:
        the compressed data (it might be larger than the input).
      • decompress

        public static byte[] decompress​(byte[] data)
                                 throws java.io.IOException
        Decompress the data.
        Returns:
        The uncompressed data.
        Throws:
        java.io.IOException - for uncompress errors.