Class AbstractAesAdapter

java.lang.Object
com.gigaspaces.client.storage_adapters.PropertyStorageAdapter
com.gigaspaces.client.storage_adapters.AbstractAesAdapter
Direct Known Subclasses:
AesCbcAdapter, AesGcmAdapter

public abstract class AbstractAesAdapter extends PropertyStorageAdapter
Base class for implementing adapters which encrypt properties using AES.
Since:
15.2
Author:
Niv Ingberg
  • Field Details

    • EMPTY

      protected static final byte[] EMPTY
  • Constructor Details

    • AbstractAesAdapter

      public AbstractAesAdapter()
  • Method Details

    • getName

      public String getName()
      Description copied from class: PropertyStorageAdapter
      Returns a name used for display in monitoring tools.
      Overrides:
      getName in class PropertyStorageAdapter
    • getStorageClass

      public Class<?> getStorageClass()
      Description copied from class: PropertyStorageAdapter
      Returns the class of the values which will be stored in the space.
      Overrides:
      getStorageClass in class PropertyStorageAdapter
    • toSpace

      public Object toSpace(Object value) throws IOException
      Description copied from class: PropertyStorageAdapter
      Triggered when a property value is retrieved from the user's object and is about to be sent to the space.
      Specified by:
      toSpace in class PropertyStorageAdapter
      Parameters:
      value - The original property value
      Returns:
      The value which should be stored in space
      Throws:
      IOException - Thrown when processing the property value fails.
    • fromSpace

      public Object fromSpace(Object value) throws IOException, ClassNotFoundException
      Description copied from class: PropertyStorageAdapter
      Triggered when a property value arrives from the space and is about to be injected in the user's object.
      Specified by:
      fromSpace in class PropertyStorageAdapter
      Parameters:
      value - The value which was stored in the space
      Returns:
      The value which should be set in the user's object.
      Throws:
      IOException - Thrown when processing the property value fails.
      ClassNotFoundException - Thrown when processing the property value fails due to a class loading issue.
    • getPassPhrase

      protected byte[] getPassPhrase() throws GeneralSecurityException
      Returns the pass phrase which is used to generate the encryption key and mac key. Note: The default implementation loads the pass phrase from system property, which is not considered a secured location for secrets. It's highly recommended to override this method and load the pass phrase from a secure location of your choice.
      Throws:
      GeneralSecurityException
    • getSecureRandom

      protected Random getSecureRandom()
    • initSecureRandom

      protected Random initSecureRandom()
    • initTransformation

      protected abstract String initTransformation()
      Provides the cipher transformation string.
    • initIvLengthBytes

      protected abstract int initIvLengthBytes()
      Provides the initialization vector length, in bytes.
    • initEncryptionAlgorithm

      protected String initEncryptionAlgorithm()
      Provides the encryption algorithm.
    • initEncryptionKeyLength

      protected int initEncryptionKeyLength()
      Provides the encryption key length, in bytes.
    • encrypt

      protected byte[] encrypt(byte[] plainText) throws GeneralSecurityException
      Encrypts the provided plainText, and packs it with the iv and mac.
      Throws:
      GeneralSecurityException
    • decrypt

      protected byte[] decrypt(byte[] data) throws GeneralSecurityException
      Unpacks the data to iv, ciphertext, mac, validates and decrypts.
      Throws:
      GeneralSecurityException
    • generateInitializationVector

      protected byte[] generateInitializationVector(int length)
      Generate initialization vector for encryption. NOTE: Security best practices dictate that you should not reuse an IV with the same key, as this can be exploited to discover the key, hence the default implementation produces a random IV. As a result, the encryption output is not deterministic, which means encrypted properties cannot be used in queries. If querying is required and the security risk is acceptable for your use case, you can override this property and provide a deterministic initialization vector (constant or content-related).
    • cipher

      protected byte[] cipher(byte[] iv, byte[] input, int mode) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • getOrCreateCipher

      protected Cipher getOrCreateCipher() throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • toParameterSpec

      protected AlgorithmParameterSpec toParameterSpec(byte[] iv)
    • initMacEnabled

      protected abstract boolean initMacEnabled()
    • initMacAlgorithm

      protected String initMacAlgorithm()
    • initMacKeyLength

      protected int initMacKeyLength()
    • generateMac

      protected byte[] generateMac(byte[] cipherText, byte[] iv) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • getOrCreateMac

      protected Mac getOrCreateMac() throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • generateSubKey

      protected SecretKey generateSubKey(String subKey, int length, String algorithm) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • generateSubKey

      protected byte[] generateSubKey(byte[] rawKey, int length, byte[] salt, byte[] subKey) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • writeArrayWithByteLength

      protected static void writeArrayWithByteLength(ByteBuffer byteBuffer, byte[] array)
    • readArrayWithByteLength

      protected static byte[] readArrayWithByteLength(ByteBuffer byteBuffer)
    • writeArrayRemaining

      protected static void writeArrayRemaining(ByteBuffer byteBuffer, byte[] array)
    • readArrayRemaining

      protected static byte[] readArrayRemaining(ByteBuffer byteBuffer)