Class Decryptor

java.lang.Object
com.mku.salmon.Decryptor

public class Decryptor extends Object
Utility class that decrypts byte arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate an encryptor.
    Decryptor(int threads)
    Instantiate an encryptor with parallel tasks and buffer size.
    Decryptor(int threads, int bufferSize)
    Instantiate an encryptor with parallel tasks and buffer size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the decryptor and release associated resources
    byte[]
    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.

    Methods inherited from class java.lang.Object

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

    • 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 Details

    • decrypt

      public byte[] decrypt(byte[] data, byte[] key) throws 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:
      IOException - Thrown if there is an error with the stream.
      SecurityException - Thrown if there is a security exception
      IntegrityException - Thrown if the data are corrupt or tampered with.
    • decrypt

      public byte[] decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format) throws 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, see EncryptionFormat
      Returns:
      The output buffer containing the decrypted data.
      Throws:
      IOException - Thrown if there is an error with the stream.
      SecurityException - Thrown if there is a security exception
      IntegrityException - Thrown if the data are corrupt or tampered with.
    • decrypt

      public byte[] decrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity) throws 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, see EncryptionFormat
      integrity - Verify hash integrity in the data.
      Returns:
      The byte array with the decrypted data.
      Throws:
      IOException - Thrown if there is a problem with decoding the array.
      SecurityException - Thrown if the key and nonce are not provided.
      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 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, see EncryptionFormat
      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:
      IOException - Thrown if there is a problem with decoding the array.
      SecurityException - Thrown if the key and nonce are not provided.
      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 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, see EncryptionFormat
      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:
      IOException - Thrown if there is a problem with decoding the array.
      SecurityException - Thrown if the key and nonce are not provided.
      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