Interface CryptoEngine
-
- All Known Implementing Classes:
DatabaseBackedCryptoEngine,InMemoryCryptoEngine,JavaKeyStoreCryptoEngine,JdbcCryptoEngine,JpaCryptoEngine,PKCS11CryptoEngine,VaultCryptoEngine
public interface CryptoEngineInterface towards the cryptographic functionality needed by the Axon Data Protection Module. The module provides functionality for retrieval, generation/storage and deletion of AES-256 keys, and obtaining a Cipher object to perform encryption and decryption using aSecretKey. The Axon Data Protection Module offers various implementations for this interface, including an in-memory implementation for test, an implementation that stored keys in a database, and an implementation that works with a hardware security module (HSM).Both the
SecretKeymanagement functionality and obtaining aCiphermust be in a single interface to support those cases where HSMs are used. In those cases, a SecretKey object won't contain any actual key material. Instead it's just a reference to a secret key stored on the device. The Cipher object interfacing to the HSM will be able to deal with this.In principle, we could have directly used the
ProviderandKeyStoreabstractions instead of this one. This would have led to unnecessary complexity in the most common use case where keys are stored in a regular database. Therefore, this simpler abstraction is offered instead.Implementations of this class are responsible for selecting the symmetric encryption algorithm, mode, padding, and key length. All standard implementations in the Axon Data Protection Module use AES in CBC mode with PKCS#5 padding and a 256-bit key length.
- See Also:
InMemoryCryptoEngine,JavaKeyStoreCryptoEngine
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CiphercreateCipher()Creates an uninitializedCipherinstance for the correct transformation (AES, CBC, PKCS#5) and provider.CiphercreateDigestCipher()Creates an uninitializedCipherinstance for calculating the encrypted digest.voiddeleteKey(String id)Deletes the key for a given id.SecretKeygetKey(String id)Retrieves the key for a given id.KeyTypegetKeyType()Retrieves the currently usedKeyTypefor new keysSecretKeygetOrCreateKey(String id)Retrieves the key for a given id.voidsetKeyType(KeyType keyType)Sets theKeyTypeto use, which determines the length of newly generated keys.
-
-
-
Method Detail
-
getOrCreateKey
SecretKey getOrCreateKey(String id)
Retrieves the key for a given id. If no such key is registered, generates a new random key and stores it under the alias before returning it.
-
deleteKey
void deleteKey(String id)
Deletes the key for a given id. Does nothing if the key doesn't exist.- Parameters:
id- the id of theSecretKey
-
createCipher
Cipher createCipher()
Creates an uninitializedCipherinstance for the correct transformation (AES, CBC, PKCS#5) and provider. Clients should still call theCipher.init(int, java.security.Key, AlgorithmParameterSpec)to specify operation mode (encryption or decryption), key and initialization vector.- Returns:
- the
Cipher
-
createDigestCipher
Cipher createDigestCipher()
Creates an uninitializedCipherinstance for calculating the encrypted digest. For this specific purpose, it should use AES, EBC and no padding, and the same provider as for the other operations. Clients should still call theCipher.init(int, java.security.Key)to specify operation mode (always encryption) and key.- Returns:
- the
Cipher
-
setKeyType
void setKeyType(KeyType keyType)
Sets theKeyTypeto use, which determines the length of newly generated keys. Defaults toKeyType.AES_256if not set.- Parameters:
keyType- the newKeyType
-
-