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 StringdefaultKeyAlgorithmstatic StringERROR_KEY_GET_KEY_ERRORstatic StringERROR_KEY_KEY_STORE_LOAD_ERRORstatic StringERROR_KEY_KEY_STORE_STORE_ERRORstatic StringERROR_KEY_SAVE_KEY_ERRORstatic StringKEY_STORE_TYPEprotected KeyStorekeyStoreprotected FilekeyStoreFileprotected char[]keyStorePasswordstatic StringLOG_KEY_KEY_CREATEDstatic StringLOG_KEY_KEY_FOUNDstatic StringLOG_KEY_KEY_NOT_FOUNDstatic StringLOG_KEY_KEY_SAVEDstatic StringLOG_KEY_KEY_STORE_LOADEDstatic StringLOG_KEY_KEY_STORE_STORED
-
Constructor Summary
Constructors Constructor Description SecretKeyRepositoryImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()SecretKeygetKey(String name, boolean create)Returns the secret key for the specified key nameprotected voidloadKeyStore()voidsaveKey(String name, SecretKey key)Saves the secret key in the repository, with the specified namevoidsetDefaultKeyAlgorithm(String defaultKeyAlgorithm)voidsetKeyStoreFile(File keyStoreFile)voidsetKeyStorePassword(String keyStorePassword)protected voidstoreKeyStore()
-
-
-
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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
CryptoException
-
getKey
public SecretKey getKey(String name, boolean create) throws CryptoException
Description copied from interface:SecretKeyRepositoryReturns the secret key for the specified key name- Specified by:
getKeyin 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:SecretKeyRepositorySaves the secret key in the repository, with the specified name- Specified by:
saveKeyin 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
-
-