Class EncoderDecoder

java.lang.Object
de.das.encrypter.processors.EncoderDecoder

public class EncoderDecoder extends Object
This class provides methods for encryption and decryption using the unique and random keys created by this factory.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    decrypt(byte[] data)
    Assumes that the specified byte array is encrypted and attempts to decrypt the data using the key whose ID is in the header of the encrypted data.
    byte[]
    decrypt(byte[] key, byte[] data)
    Assumes that the given byte array is encrypted with the given key and tries to decrypt this data.
    byte[]
    encrypt(long entryPoint, byte[] key, byte[] data)
    Encrypts the specified data using the specified key, with key usage starting at the specified entry position.
    byte[]
    encrypt(long entryPoint, byte[] key, byte[] data, String fileName)
    Encrypts the specified data using the specified key, with key usage starting at the specified entry position.
    byte[]
    encrypt(long keyId, byte[] pureKey, long entryPoint, byte[] data, String fileName)
    This encryption method assumes that the given key is a part of the key identified by the given ID started at the given entry point position.
    static String
    getDecryptedFileName(byte[] econtent)
    Extracts the decrypted name of the original unencrypted file.
    static byte[]
    getEncryptedFileName(byte[] econtent)
    Extracts the encrypted name of the original unencrypted file from the header of the given encrypted data.
    static String
    Extracts and decrypts the name of the original unencrypted file from the header of a file with encrypted data.
    static String
    Determines the original folder name of the given folder with an cryptic name.
    static String
    getFolderName(String path, String lastFolder)
    Determines the original folder name of the the given path with the cryptic name.
    byte[]
    getKeyById(String folder, long keyId)
    Search in the given folder for a file with the key prefix and the given key identifier.
    static long
    getKeyEntryPoint(byte[] content)
    Provides the random entry point into the key.
    static long
    Provides the random entry point into the key.
    static long
    getKeyId(byte[] content)
    Extracts the key ID from an byte array containing encrypted data.
    long
    Extracts the key ID from an encrypted file.
    byte[]
    getPureEncryptedData(byte[] eData)
    Extracts the pure encrypted data what means the part of the given data without the header.
    static boolean
    isEncrypted(byte[] buffer)
    Checks the given buffer content, if it starts with the legal prefix of an encrypted file.
    boolean
    Checks the given file content, if it starts with the legal prefix of an encrypted file.
    static void
    Static method for commissioning the encoder-decoder, which provides the processor with the keys known to the system.
    static void
    setup(String name, KeyFiles kfs)
    Static method for commissioning the encoder-decoder, which provides the processor with the keys known to the system.

    Methods inherited from class java.lang.Object

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

    • EncoderDecoder

      public EncoderDecoder()
  • Method Details

    • setup

      public static void setup(KeyFiles kfs)
      Static method for commissioning the encoder-decoder, which provides the processor with the keys known to the system. The name substitution for folder names that cannot be decrypted is set to "".
      Parameters:
      kfs - the instance of the hash map with the known key files.
    • setup

      public static void setup(String name, KeyFiles kfs)
      Static method for commissioning the encoder-decoder, which provides the processor with the keys known to the system.
      Parameters:
      name - a string or character used when trying to decrypt encrypted folder names and the decryption fails (e.g. the character ).
      kfs - the instance of the hash map with the known key files.
    • getFolderName

      public static String getFolderName(File f)
      Determines the original folder name of the given folder with an cryptic name.
      Parameters:
      f - an folder with an encrypted name.
      Returns:
      the original unencrypted folder name.
    • getFolderName

      public static String getFolderName(String path, String lastFolder)
      Determines the original folder name of the the given path with the cryptic name.
      Parameters:
      path - the path to a folder with an encrypted name.
      lastFolder - the file name of the file containing the encrypted original folder name.
      Returns:
      the original unencrypted folder name.
    • getKeyId

      public long getKeyId(File f) throws Exception, NotEncryptedException
      Extracts the key ID from an encrypted file.
      Parameters:
      f - a file with encrypted data.
      Returns:
      the ID of the required key for the decryption.
      Throws:
      NotEncryptedException - if the given data are not encrypted.
      Exception - in case of any error or if the file does not contain encrypted data.
    • getKeyId

      public static long getKeyId(byte[] content) throws Exception, NotEncryptedException
      Extracts the key ID from an byte array containing encrypted data.
      Parameters:
      content - a byte array of encrypted data.
      Returns:
      the ID of the key required for the decryption of the given encrypted data.
      Throws:
      NotEncryptedException - if the given data are not encrypted.
      Exception - in case of any other error.
    • getKeyEntryPoint

      public static long getKeyEntryPoint(File f) throws Exception
      Provides the random entry point into the key.
      Parameters:
      f - a file with encrypted data.
      Returns:
      the entry point into the encryption key.
      Throws:
      Exception - in case of any error.
    • getKeyEntryPoint

      public static long getKeyEntryPoint(byte[] content) throws Exception
      Provides the random entry point into the key.
      Parameters:
      content - a byte array of encrypted data.
      Returns:
      the entry point into the encryption key.
      Throws:
      Exception - in case of any error.
    • decrypt

      public byte[] decrypt(byte[] data) throws NoKeyAvailableException, Exception
      Assumes that the specified byte array is encrypted and attempts to decrypt the data using the key whose ID is in the header of the encrypted data.
      Parameters:
      data - a byte array with encrypted data.
      Returns:
      the decrypted data.
      Throws:
      NoKeyAvailableException - if no key with the ID contained in the header of the encrypted data is available.
      Exception - if any other error occurs.
    • decrypt

      public byte[] decrypt(byte[] key, byte[] data) throws Exception
      Assumes that the given byte array is encrypted with the given key and tries to decrypt this data.
      Parameters:
      key - a given key.
      data - a byte array with encrypted data.
      Returns:
      the decrypted data.
      Throws:
      Exception - in case of a failed decryption.
    • encrypt

      public byte[] encrypt(long entryPoint, byte[] key, byte[] data) throws InvalidKeyException, Exception
      Encrypts the specified data using the specified key, with key usage starting at the specified entry position. The encrypted data is preceded by a header, by which it can be recognized that it is encrypted data, with which key (key ID) it was encrypted, from which position the bytes of the key are to be used and what the file with the unencrypted data was called.
      Parameters:
      entryPoint - the position where to start using byte in the key.
      key - a valid encryption key.
      data - the data to be encrypted. null if not used.
      Returns:
      a byte array with the encrypted data.
      Throws:
      InvalidKeyException - if the key is invalid.
      Exception - in all other error cases.
    • encrypt

      public byte[] encrypt(long entryPoint, byte[] key, byte[] data, String fileName) throws InvalidKeyException, Exception
      Encrypts the specified data using the specified key, with key usage starting at the specified entry position. The encrypted data is preceded by a header, by which it can be recognized that it is encrypted data, with which key (key ID) it was encrypted, from which position the bytes of the key are to be used and what the file with the unencrypted data was called.
      Parameters:
      entryPoint - the position where to start using byte in the key.
      key - a valid encryption key.
      data - the data to be encrypted.
      fileName - the name of the the file where the data come from or null if not used.
      Returns:
      a byte array with the encrypted data.
      Throws:
      InvalidKeyException - if the key is invalid.
      Exception - in all other error cases.
    • encrypt

      public byte[] encrypt(long keyId, byte[] pureKey, long entryPoint, byte[] data, String fileName) throws InvalidKeyException, Exception
      This encryption method assumes that the given key is a part of the key identified by the given ID started at the given entry point position. So it encrypts the given data with the pure key data and inserts key ID and entry point in the encryption header.
      Parameters:
      keyId -
      pureKey -
      entryPoint -
      data -
      Returns:
      Throws:
      InvalidKeyException
      Exception
    • getKeyById

      public byte[] getKeyById(String folder, long keyId)
      Search in the given folder for a file with the key prefix and the given key identifier.
      Parameters:
      folder - a given folder.
      keyId - the key identifier.
      Returns:
      the key file content or null, if no suitable file could be found.
    • isEncrypted

      public static boolean isEncrypted(byte[] buffer)
      Checks the given buffer content, if it starts with the legal prefix of an encrypted file.
      Parameters:
      buffer - the first 40 bytes of a file.
      Returns:
      true, if the given buffer content contains the legal prefix of an encrypted file.
    • isEncrypted

      public boolean isEncrypted(File f) throws Exception
      Checks the given file content, if it starts with the legal prefix of an encrypted file.
      Parameters:
      f - a given file.
      Returns:
      true, if the given file content starts with the legal prefix of an encrypted file.
      Throws:
      Exception - in case of any error.
    • getFileName

      public static String getFileName(String path)
      Extracts and decrypts the name of the original unencrypted file from the header of a file with encrypted data.
      Parameters:
      path - the path of a file with encrypted data.
      Returns:
      the name of the original unencrypted file.
    • getDecryptedFileName

      public static String getDecryptedFileName(byte[] econtent) throws Exception
      Extracts the decrypted name of the original unencrypted file.
      Parameters:
      econtent - the bytes of encrypted data.
      Returns:
      the decrypted name of the original unencrypted file.
      Throws:
      Exception - in case of any error.
    • getEncryptedFileName

      public static byte[] getEncryptedFileName(byte[] econtent)
      Extracts the encrypted name of the original unencrypted file from the header of the given encrypted data.
      Parameters:
      econtent - a byte array with encrypted data.
      Returns:
      the encrypted name of the original unencrypted file from the header of the given encrypted data.
    • getPureEncryptedData

      public byte[] getPureEncryptedData(byte[] eData) throws Exception
      Extracts the pure encrypted data what means the part of the given data without the header.
      Parameters:
      eData - the encrypted data inclusive its header.
      Returns:
      the pure encrypted data without its header.
      Throws:
      Exception