Class JavaKeyStoreCryptoEngine
- java.lang.Object
-
- io.axoniq.dataprotection.cryptoengine.JavaKeyStoreCryptoEngine
-
- All Implemented Interfaces:
CryptoEngine
- Direct Known Subclasses:
PKCS11CryptoEngine
public class JavaKeyStoreCryptoEngine extends Object implements CryptoEngine
Implementation ofCryptoEnginethat uses a JCEKeyStoreimplementation to store its keys. It will examine the givenKeyStorefor itsProvider, and then obtain aKeyGeneratorandCipherobject from this provider as well. Please note the default JavaKeyStoreimplementation used for instance to store certificates for a web server, is totally unsuitable for this particular application. The main reason why this class exists is as a stepping stone to implement the PKCS#11 implementationPKCS11CryptoEngine.Please note that the implementation will not call
KeyStore.store(KeyStore.LoadStoreParameter)orKeyStore.store(OutputStream, char[])after a call togetOrCreateKey(String). It assumes that aKeyStoretype is used that will save keys immediately, which is true of PKCS#11 key stores, but not of a standard file-based key store.
-
-
Constructor Summary
Constructors Constructor Description JavaKeyStoreCryptoEngine(KeyStore keyStore)Constructs a newJavaKeyStoreCryptoEngine
-
Method Summary
All Methods Instance Methods Concrete 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.
-
-
-
Constructor Detail
-
JavaKeyStoreCryptoEngine
public JavaKeyStoreCryptoEngine(KeyStore keyStore)
Constructs a newJavaKeyStoreCryptoEngine- Parameters:
keyStore- theKeyStoreto use
-
-
Method Detail
-
getOrCreateKey
public 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. Please see the class description for a caveat on key saving.- Specified by:
getOrCreateKeyin interfaceCryptoEngine- Parameters:
id- the id of theSecretKey- Returns:
- the potentially new
SecretKeyassociated with the id
-
getKey
public SecretKey getKey(String id)
Description copied from interface:CryptoEngineRetrieves the key for a given id.- Specified by:
getKeyin interfaceCryptoEngine- Parameters:
id- the id of theSecretKey- Returns:
- the existing
SecretKeyassociated with the id, ornullif no such key exists
-
deleteKey
public void deleteKey(String id)
Description copied from interface:CryptoEngineDeletes the key for a given id. Does nothing if the key doesn't exist.- Specified by:
deleteKeyin interfaceCryptoEngine- Parameters:
id- the id of theSecretKey
-
createCipher
public Cipher createCipher()
Description copied from interface:CryptoEngineCreates 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.- Specified by:
createCipherin interfaceCryptoEngine- Returns:
- the
Cipher
-
createDigestCipher
public Cipher createDigestCipher()
Description copied from interface:CryptoEngineCreates 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.- Specified by:
createDigestCipherin interfaceCryptoEngine- Returns:
- the
Cipher
-
setKeyType
public void setKeyType(KeyType keyType)
Description copied from interface:CryptoEngineSets theKeyTypeto use, which determines the length of newly generated keys. Defaults toKeyType.AES_256if not set.- Specified by:
setKeyTypein interfaceCryptoEngine- Parameters:
keyType- the newKeyType
-
getKeyType
public KeyType getKeyType()
Description copied from interface:CryptoEngineRetrieves the currently usedKeyTypefor new keys- Specified by:
getKeyTypein interfaceCryptoEngine- Returns:
- the current value
-
-