Package com.mku.salmon
Class Decryptor
- java.lang.Object
-
- com.mku.salmon.Decryptor
-
public class Decryptor extends java.lang.Object
Utility class that decrypts byte arrays.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the decryptor and release associated resourcesbyte[]
decrypt(byte[] data, byte[] key)
Decrypts a byte array using the embedded nonce.byte[]
decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format)
Decrypts a byte array.byte[]
decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity)
Decrypt a byte array using the specified nonce and integrity.byte[]
decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey)
Decrypt a byte array using the specified nonce and integrity hash key.byte[]
decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey, int chunkSize)
Decrypt a byte array using the specified nonce, the integrity hash key and the chunk size.
-
-
-
Constructor Detail
-
Decryptor
public Decryptor()
Instantiate an encryptor.
-
Decryptor
public Decryptor(int threads)
Instantiate an encryptor with parallel tasks and buffer size.- Parameters:
threads
- The number of threads to use.
-
Decryptor
public Decryptor(int threads, int bufferSize)
Instantiate an encryptor with parallel tasks and buffer size.- Parameters:
threads
- The number of threads to use.bufferSize
- The buffer size to use. It is recommended for performance to use a multiple of the chunk size if you enabled integrity otherwise a multiple of the AES block size (16 bytes).
-
-
Method Detail
-
decrypt
public byte[] decrypt(byte[] data, byte[] key) throws java.io.IOException
Decrypts a byte array using the embedded nonce.- Parameters:
data
- The input data to be decrypted.key
- The AES key to use for decryption.- Returns:
- The output buffer containing the decrypted data.
- Throws:
java.io.IOException
- Thrown if there is an error with the stream.SecurityException
- Thrown if there is a security exceptionIntegrityException
- Thrown if the data are corrupt or tampered with.
-
decrypt
public byte[] decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format) throws java.io.IOException
Decrypts a byte array.- Parameters:
data
- The input data to be decrypted.key
- The AES key to use for decryption.nonce
- The nonce to use for decryption.format
- The format to use, seeEncryptionFormat
- Returns:
- The output buffer containing the decrypted data.
- Throws:
java.io.IOException
- Thrown if there is an error with the stream.SecurityException
- Thrown if there is a security exceptionIntegrityException
- Thrown if the data are corrupt or tampered with.
-
decrypt
public byte[] decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity) throws java.io.IOException
Decrypt a byte array using the specified nonce and integrity.- Parameters:
data
- The input data to be decrypted.key
- The AES key to use for decryption.nonce
- The nonce to use for decryption.format
- The format to use, seeEncryptionFormat
integrity
- Verify hash integrity in the data.- Returns:
- The byte array with the decrypted data.
- Throws:
java.io.IOException
- Thrown if there is a problem with decoding the array.SecurityException
- Thrown if the key and nonce are not provided.java.io.IOException
- Thrown if there is an IO error.IntegrityException
- Thrown if the data are corrupt or tampered with.
-
decrypt
public byte[] decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey) throws java.io.IOException
Decrypt a byte array using the specified nonce and integrity hash key.- Parameters:
data
- The input data to be decrypted.key
- The AES key to use for decryption.nonce
- The nonce to use for decryption.format
- The format to use, seeEncryptionFormat
integrity
- Verify hash integrity in the data.hashKey
- The hash key to be used for integrity.- Returns:
- The byte array with the decrypted data.
- Throws:
java.io.IOException
- Thrown if there is a problem with decoding the array.SecurityException
- Thrown if the key and nonce are not provided.java.io.IOException
- Thrown if there is an IO error.IntegrityException
- Thrown if the data are corrupt or tampered with.
-
decrypt
public byte[] decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey, int chunkSize) throws java.io.IOException
Decrypt a byte array using the specified nonce, the integrity hash key and the chunk size.- Parameters:
data
- The input data to be decrypted.key
- The AES key to use for decryption.nonce
- The nonce to use for decryption.format
- The format to use, seeEncryptionFormat
integrity
- Verify hash integrity in the data.hashKey
- The hash key to be used for integrity.chunkSize
- The chunk size.- Returns:
- The byte array with the decrypted data.
- Throws:
java.io.IOException
- Thrown if there is a problem with decoding the array.SecurityException
- Thrown if the key and nonce are not provided.java.io.IOException
- Thrown if there is an IO error.IntegrityException
- Thrown if the data are corrupt or tampered with.
-
close
public void close()
Close the decryptor and release associated resources
-
-