Package de.das.encrypter.processors
Class EncoderDecoder
java.lang.Object
de.das.encrypter.processors.EncoderDecoder
This class provides methods for encryption and decryption using the unique
and random keys created by this factory.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]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[]Encrypts the specified data using the specified key, with key usage starting at the specified entry position.byte[]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 StringgetDecryptedFileName(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 StringgetFileName(String path) Extracts and decrypts the name of the original unencrypted file from the header of a file with encrypted data.static StringDetermines the original folder name of the given folder with an cryptic name.static StringgetFolderName(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 longgetKeyEntryPoint(byte[] content) Provides the random entry point into the key.static longProvides the random entry point into the key.static longgetKeyId(byte[] content) Extracts the key ID from an byte array containing encrypted data.longExtracts 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 booleanisEncrypted(byte[] buffer) Checks the given buffer content, if it starts with the legal prefix of an encrypted file.booleanisEncrypted(File f) Checks the given file content, if it starts with the legal prefix of an encrypted file.static voidStatic method for commissioning the encoder-decoder, which provides the processor with the keys known to the system.static voidStatic method for commissioning the encoder-decoder, which provides the processor with the keys known to the system.
-
Constructor Details
-
EncoderDecoder
public EncoderDecoder()
-
-
Method Details
-
setup
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
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
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
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
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
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
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
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
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
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:
InvalidKeyExceptionException
-
getKeyById
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
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
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
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
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
-