Class AbstractAesAdapter
java.lang.Object
com.gigaspaces.client.storage_adapters.PropertyStorageAdapter
com.gigaspaces.client.storage_adapters.AbstractAesAdapter
- Direct Known Subclasses:
AesCbcAdapter,AesGcmAdapter
Base class for implementing adapters which encrypt properties using AES.
- Since:
- 15.2
- Author:
- Niv Ingberg
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]cipher(byte[] iv, byte[] input, int mode) protected byte[]decrypt(byte[] data) Unpacks the data to iv, ciphertext, mac, validates and decrypts.protected byte[]encrypt(byte[] plainText) Encrypts the provided plainText, and packs it with the iv and mac.Triggered when a property value arrives from the space and is about to be injected in the user's object.protected byte[]generateInitializationVector(int length) Generate initialization vector for encryption.protected byte[]generateMac(byte[] cipherText, byte[] iv) protected byte[]generateSubKey(byte[] rawKey, int length, byte[] salt, byte[] subKey) protected SecretKeygenerateSubKey(String subKey, int length, String algorithm) getName()Returns a name used for display in monitoring tools.protected Cipherprotected Macprotected byte[]Returns the pass phrase which is used to generate the encryption key and mac key.protected RandomClass<?>Returns the class of the values which will be stored in the space.protected StringProvides the encryption algorithm.protected intProvides the encryption key length, in bytes.protected abstract intProvides the initialization vector length, in bytes.protected Stringprotected abstract booleanprotected intprotected Randomprotected abstract StringProvides the cipher transformation string.protected static byte[]readArrayRemaining(ByteBuffer byteBuffer) protected static byte[]readArrayWithByteLength(ByteBuffer byteBuffer) protected AlgorithmParameterSpectoParameterSpec(byte[] iv) Triggered when a property value is retrieved from the user's object and is about to be sent to the space.protected static voidwriteArrayRemaining(ByteBuffer byteBuffer, byte[] array) protected static voidwriteArrayWithByteLength(ByteBuffer byteBuffer, byte[] array) Methods inherited from class com.gigaspaces.client.storage_adapters.PropertyStorageAdapter
base64Decode, base64Encode, deserialize, serialize, supportsEqualsMatching, supportsOrderedMatching, toBinaryWrapper, unwrapBinary, unzip, useBase64Wrapper, wrapBinary, zip
-
Field Details
-
EMPTY
protected static final byte[] EMPTY
-
-
Constructor Details
-
AbstractAesAdapter
public AbstractAesAdapter()
-
-
Method Details
-
getName
Description copied from class:PropertyStorageAdapterReturns a name used for display in monitoring tools.- Overrides:
getNamein classPropertyStorageAdapter
-
getStorageClass
Description copied from class:PropertyStorageAdapterReturns the class of the values which will be stored in the space.- Overrides:
getStorageClassin classPropertyStorageAdapter
-
toSpace
Description copied from class:PropertyStorageAdapterTriggered when a property value is retrieved from the user's object and is about to be sent to the space.- Specified by:
toSpacein classPropertyStorageAdapter- 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
Description copied from class:PropertyStorageAdapterTriggered when a property value arrives from the space and is about to be injected in the user's object.- Specified by:
fromSpacein classPropertyStorageAdapter- 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
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
-
initSecureRandom
-
initTransformation
Provides the cipher transformation string. -
initIvLengthBytes
protected abstract int initIvLengthBytes()Provides the initialization vector length, in bytes. -
initEncryptionAlgorithm
Provides the encryption algorithm. -
initEncryptionKeyLength
protected int initEncryptionKeyLength()Provides the encryption key length, in bytes. -
encrypt
Encrypts the provided plainText, and packs it with the iv and mac.- Throws:
GeneralSecurityException
-
decrypt
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
- Throws:
GeneralSecurityException
-
getOrCreateCipher
- Throws:
GeneralSecurityException
-
toParameterSpec
-
initMacEnabled
protected abstract boolean initMacEnabled() -
initMacAlgorithm
-
initMacKeyLength
protected int initMacKeyLength() -
generateMac
- Throws:
GeneralSecurityException
-
getOrCreateMac
- 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
-
readArrayWithByteLength
-
writeArrayRemaining
-
readArrayRemaining
-