Class Encryptor

java.lang.Object
com.mku.salmon.Encryptor

public class Encryptor extends Object
Encrypts byte arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate an encryptor.
    Encryptor(int threads)
    Instantiate an encryptor with parallel tasks and buffer size.
    Encryptor(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[]
    encrypt(byte[] data, byte[] key, byte[] nonce)
    Encrypt a byte array and embedded the nonce.
    byte[]
    encrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format)
    Encrypt a byte array.
    byte[]
    encrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey)
    Encrypts a byte array using the nonce, the integrity hash key.
    byte[]
    encrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey, int chunkSize)
    Encrypts a byte array using the 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

    • Encryptor

      public Encryptor()
      Instantiate an encryptor.
    • Encryptor

      public Encryptor(int threads)
      Instantiate an encryptor with parallel tasks and buffer size.
      Parameters:
      threads - The number of threads to use.
    • Encryptor

      public Encryptor(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

    • encrypt

      public byte[] encrypt(byte[] data, byte[] key, byte[] nonce) throws IOException
      Encrypt a byte array and embedded the nonce.
      Parameters:
      data - The data to encrypt.
      key - The key to use.
      nonce - Nonce to use.
      Returns:
      The encrypted data
      Throws:
      SecurityException - Thrown if there is a security exception
      IntegrityException - Thrown if the data are corrupt or tampered with.
      IOException - Thrown if there is an IO error.
    • encrypt

      public byte[] encrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format) throws IOException
      Encrypt a byte array.
      Parameters:
      data - The data to encrypt.
      key - The key to use.
      nonce - Nonce to use.
      format - The format to use, see EncryptionFormat
      Returns:
      The encrypted data
      Throws:
      SecurityException - Thrown if there is a security exception
      IntegrityException - Thrown if the data are corrupt or tampered with.
      IOException - Thrown if there is an IO error.
    • encrypt

      public byte[] encrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey) throws IOException
      Encrypts a byte array using the nonce, the integrity hash key.
      Parameters:
      data - The byte array to be encrypted.
      key - The AES key to be used.
      nonce - The nonce to be used.
      format - The format to use, see EncryptionFormat
      integrity - True if you want to calculate and store hash signatures for each chunkSize.
      hashKey - Hash key to be used for all chunks.
      Returns:
      The byte array with the encrypted data.
      Throws:
      SecurityException - Thrown if there is a security exception
      IOException - Thrown if there is an IO error.
      IntegrityException - Thrown if the data are corrupt or tampered with.
    • encrypt

      public byte[] encrypt(byte[] data, byte[] key, byte[] nonce, EncryptionFormat format, boolean integrity, byte[] hashKey, int chunkSize) throws IOException
      Encrypts a byte array using the nonce, the integrity hash key, and the chunk size.
      Parameters:
      data - The byte array to be encrypted.
      key - The AES key to be used.
      nonce - The nonce to be used.
      format - The format to use, see EncryptionFormat
      integrity - True if you want to calculate and store hash signatures for each chunkSize.
      hashKey - Hash key to be used for all chunks.
      chunkSize - The chunk size.
      Returns:
      The byte array with the encrypted data.
      Throws:
      SecurityException - Thrown if there is a security exception
      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