Class SalmonEncryptor

java.lang.Object
com.mku.salmon.SalmonEncryptor

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

    Constructors
    Constructor
    Description
    Instantiate an encryptor.
    SalmonEncryptor(int threads)
    Instantiate an encryptor with parallel tasks and buffer size.
    SalmonEncryptor(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, boolean storeHeaderData)
    Encrypt a byte array.
    byte[]
    encrypt(byte[] data, byte[] key, byte[] nonce, boolean storeHeaderData, boolean integrity, byte[] hashKey, Integer chunkSize)
    Encrypts a byte array using the provided key and nonce.
    protected void
     

    Methods inherited from class java.lang.Object

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

    • SalmonEncryptor

      public SalmonEncryptor()
      Instantiate an encryptor.
    • SalmonEncryptor

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

      public SalmonEncryptor(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, boolean storeHeaderData) throws IOException
      Encrypt a byte array.
      Parameters:
      data - The data to encrypt.
      key - The key to use.
      nonce - Nonce to use.
      storeHeaderData - True to store header data in output byte array.
      Returns:
      The encrypted data
      Throws:
      SalmonSecurityException - 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, boolean storeHeaderData, boolean integrity, byte[] hashKey, Integer chunkSize) throws IOException
      Encrypts a byte array using the provided key and nonce.
      Parameters:
      data - The byte array to be encrypted.
      key - The AES key to be used.
      nonce - The nonce to be used.
      storeHeaderData - True if you want to store a header data with the nonce. False if you store the nonce external. Note that you will need to provide the nonce when decrypting.
      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:
      SalmonSecurityException - 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
    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object