Class SecretKeyRepositoryImpl
- java.lang.Object
-
- org.craftercms.commons.crypto.impl.SecretKeyRepositoryImpl
-
- All Implemented Interfaces:
SecretKeyRepository
,org.springframework.beans.factory.InitializingBean
public class SecretKeyRepositoryImpl extends Object implements SecretKeyRepository, org.springframework.beans.factory.InitializingBean
Default implementation ofSecretKeyRepository
, which uses JCE Key Store.- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description protected String
defaultKeyAlgorithm
static String
ERROR_KEY_GET_KEY_ERROR
static String
ERROR_KEY_KEY_STORE_LOAD_ERROR
static String
ERROR_KEY_KEY_STORE_STORE_ERROR
static String
ERROR_KEY_SAVE_KEY_ERROR
static String
KEY_STORE_TYPE
protected KeyStore
keyStore
protected File
keyStoreFile
protected char[]
keyStorePassword
static String
LOG_KEY_KEY_CREATED
static String
LOG_KEY_KEY_FOUND
static String
LOG_KEY_KEY_NOT_FOUND
static String
LOG_KEY_KEY_SAVED
static String
LOG_KEY_KEY_STORE_LOADED
static String
LOG_KEY_KEY_STORE_STORED
-
Constructor Summary
Constructors Constructor Description SecretKeyRepositoryImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
SecretKey
getKey(String name, boolean create)
Returns the secret key for the specified key nameprotected void
loadKeyStore()
void
saveKey(String name, SecretKey key)
Saves the secret key in the repository, with the specified namevoid
setDefaultKeyAlgorithm(String defaultKeyAlgorithm)
void
setKeyStoreFile(File keyStoreFile)
void
setKeyStorePassword(String keyStorePassword)
protected void
storeKeyStore()
-
-
-
Field Detail
-
KEY_STORE_TYPE
public static final String KEY_STORE_TYPE
- See Also:
- Constant Field Values
-
LOG_KEY_KEY_FOUND
public static final String LOG_KEY_KEY_FOUND
- See Also:
- Constant Field Values
-
LOG_KEY_KEY_NOT_FOUND
public static final String LOG_KEY_KEY_NOT_FOUND
- See Also:
- Constant Field Values
-
LOG_KEY_KEY_CREATED
public static final String LOG_KEY_KEY_CREATED
- See Also:
- Constant Field Values
-
LOG_KEY_KEY_SAVED
public static final String LOG_KEY_KEY_SAVED
- See Also:
- Constant Field Values
-
LOG_KEY_KEY_STORE_LOADED
public static final String LOG_KEY_KEY_STORE_LOADED
- See Also:
- Constant Field Values
-
LOG_KEY_KEY_STORE_STORED
public static final String LOG_KEY_KEY_STORE_STORED
- See Also:
- Constant Field Values
-
ERROR_KEY_KEY_STORE_LOAD_ERROR
public static final String ERROR_KEY_KEY_STORE_LOAD_ERROR
- See Also:
- Constant Field Values
-
ERROR_KEY_KEY_STORE_STORE_ERROR
public static final String ERROR_KEY_KEY_STORE_STORE_ERROR
- See Also:
- Constant Field Values
-
ERROR_KEY_GET_KEY_ERROR
public static final String ERROR_KEY_GET_KEY_ERROR
- See Also:
- Constant Field Values
-
ERROR_KEY_SAVE_KEY_ERROR
public static final String ERROR_KEY_SAVE_KEY_ERROR
- See Also:
- Constant Field Values
-
keyStoreFile
protected File keyStoreFile
-
keyStorePassword
protected char[] keyStorePassword
-
defaultKeyAlgorithm
protected String defaultKeyAlgorithm
-
keyStore
protected KeyStore keyStore
-
-
Method Detail
-
setKeyStoreFile
public void setKeyStoreFile(File keyStoreFile)
-
setKeyStorePassword
public void setKeyStorePassword(String keyStorePassword)
-
setDefaultKeyAlgorithm
public void setDefaultKeyAlgorithm(String defaultKeyAlgorithm)
-
afterPropertiesSet
public void afterPropertiesSet() throws CryptoException
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
CryptoException
-
getKey
public SecretKey getKey(String name, boolean create) throws CryptoException
Description copied from interface:SecretKeyRepository
Returns the secret key for the specified key name- Specified by:
getKey
in interfaceSecretKeyRepository
- Parameters:
name
- the key's name in the repositorycreate
- true to create new key if there's no key with the specified name in the repository.- Returns:
- the key
- Throws:
CryptoException
-
saveKey
public void saveKey(String name, SecretKey key) throws CryptoException
Description copied from interface:SecretKeyRepository
Saves the secret key in the repository, with the specified name- Specified by:
saveKey
in interfaceSecretKeyRepository
- Parameters:
name
- the key's name in the repositorykey
- the key to save- Throws:
CryptoException
-
loadKeyStore
protected void loadKeyStore() throws CryptoException
- Throws:
CryptoException
-
storeKeyStore
protected void storeKeyStore() throws CryptoException
- Throws:
CryptoException
-
-