Package rs.baselib.crypto
Class DefaultCryptingDelegateFactory
java.lang.Object
rs.baselib.crypto.DefaultCryptingDelegateFactory
- All Implemented Interfaces:
ICryptingDelegateFactory
public class DefaultCryptingDelegateFactory extends java.lang.Object implements ICryptingDelegateFactory
Creates a crypting delegator.
This class finds its configuration via classpath. You can give java argument -Dencryption.config=path
which will then load the config from this path. The default location is encryption-config.xml.
- Author:
- ralph
-
Field Summary
Fields Modifier and Type Field Description static DefaultCryptingDelegateFactoryINSTANCE -
Method Summary
Modifier and Type Method Description protected voidcreateCryptingDelegate()Creates and initializes the crypting delegate.java.lang.StringgetAlgorithm()Returns the algorithm.protected XMLConfigurationgetConfiguration()Returns the configuration.ICryptingDelegategetCryptingDelegate()Returns a crypting delegate.protected java.lang.StringgetDelegateClassName()Returns the name of the delegate class.static ICryptingDelegateFactorygetInstance()Returns the crypting delegate factory.protected java.lang.StringgetKeyAlias()Returns the public key alias in key store.java.security.KeyPairgetKeyPair()Returns the keyPair.protected char[]getKeyPassword()Return the public key passwordprotected byte[]getKeySalt()Return the public key salt.protected java.security.KeyStoregetKeyStore()Returns the key store.protected SubnodeConfigurationgetKeyStoreConfig()Returns the configuration for the keystore.protected char[]getKeyStorePassword()Return the key store passwordprotected java.lang.StringgetKeyStorePath()Returns the key store path.protected java.lang.StringgetKeyStoreType()Returns the key store path.java.security.spec.AlgorithmParameterSpecgetParamSpec()Returns the paramSpec.char[]getPassphrase()Alternatively provide a passphrase for encryption usage.protected char[]getPassword(java.lang.String type)Asks the respective callback to deliver a password.protected IPasswordCallbackgetPasswordCallback(java.lang.String type)Returns a callback for the given type.protected SubnodeConfigurationgetPasswordCallbackConfig(java.lang.String type)Returns the configuration for the password callback.byte[]getSalt()Provide a salt for encryption usage.protected byte[]getSalt(java.lang.String type)Asks the respective callback to deliver a salt.protected voidinit()Initializes this factory.protected java.lang.StringloadAlgorithm(Configuration config)Returns the algorithm definition from the configprotected java.security.spec.AlgorithmParameterSpecloadParamSpec(Configuration config)Currently only default PBE spec.protected voidloadSpec()Loads the spec params (lazily).voidsetAlgorithm(java.lang.String algorithm)Sets the algorithm.voidsetKeyPair(java.security.KeyPair keyPair)Sets the keyPair.voidsetParamSpec(java.security.spec.AlgorithmParameterSpec paramSpec)Sets the paramSpec.
-
Field Details
-
Method Details
-
getInstance
Returns the crypting delegate factory.- Returns:
- the factory
-
init
protected void init()Initializes this factory. -
loadSpec
protected void loadSpec()Loads the spec params (lazily). -
getConfiguration
Returns the configuration.- Returns:
- the configuration
-
getDelegateClassName
protected java.lang.String getDelegateClassName()Returns the name of the delegate class.- Returns:
- the name of delegate class
-
getPasswordCallback
Returns a callback for the given type.- Parameters:
type- type of password callback- Returns:
- the password callback
-
getPasswordCallbackConfig
Returns the configuration for the password callback.- Parameters:
type- type of callback- Returns:
- classname
-
getPassword
protected char[] getPassword(java.lang.String type)Asks the respective callback to deliver a password.- Parameters:
type- type of callback- Returns:
- password or null if no callback exists.
-
getKeySalt
protected byte[] getKeySalt()Return the public key salt.- Returns:
- key salt
-
getSalt
public byte[] getSalt()Provide a salt for encryption usage.- Specified by:
getSaltin interfaceICryptingDelegateFactory- Returns:
- salt
-
getSalt
protected byte[] getSalt(java.lang.String type)Asks the respective callback to deliver a salt.- Parameters:
type- type of callback- Returns:
- salt or null if no callback exists.
-
getKeyStoreConfig
Returns the configuration for the keystore.- Returns:
- classname
-
getKeyStore
protected java.security.KeyStore getKeyStore() throws java.io.IOExceptionReturns the key store.- Returns:
- the key store
- Throws:
java.io.IOException- when key store cannot be opened
-
getKeyStoreType
protected java.lang.String getKeyStoreType()Returns the key store path.- Returns:
- key store path
-
getKeyStorePath
protected java.lang.String getKeyStorePath()Returns the key store path.- Returns:
- key store path
-
getKeyStorePassword
protected char[] getKeyStorePassword()Return the key store password- Returns:
- key store password
-
getKeyAlias
protected java.lang.String getKeyAlias()Returns the public key alias in key store.- Returns:
- key alias
-
getKeyPassword
protected char[] getKeyPassword()Return the public key password- Returns:
- key password
-
getPassphrase
public char[] getPassphrase()Alternatively provide a passphrase for encryption usage.- Specified by:
getPassphrasein interfaceICryptingDelegateFactory- Returns:
- passphrase
-
getCryptingDelegate
Returns a crypting delegate.- Specified by:
getCryptingDelegatein interfaceICryptingDelegateFactory- Returns:
- a delegate
-
createCryptingDelegate
protected void createCryptingDelegate()Creates and initializes the crypting delegate. -
getKeyPair
public java.security.KeyPair getKeyPair()Returns the keyPair.- Specified by:
getKeyPairin interfaceICryptingDelegateFactory- Returns:
- the keyPair
-
setKeyPair
public void setKeyPair(java.security.KeyPair keyPair)Sets the keyPair.- Parameters:
keyPair- the keyPair to set
-
getAlgorithm
public java.lang.String getAlgorithm()Returns the algorithm.- Specified by:
getAlgorithmin interfaceICryptingDelegateFactory- Returns:
- the algorithm
-
setAlgorithm
public void setAlgorithm(java.lang.String algorithm)Sets the algorithm.- Parameters:
algorithm- the algorithm to set
-
loadAlgorithm
Returns the algorithm definition from the config- Parameters:
config- the config- Returns:
- the algorithm
-
getParamSpec
public java.security.spec.AlgorithmParameterSpec getParamSpec()Returns the paramSpec.- Specified by:
getParamSpecin interfaceICryptingDelegateFactory- Returns:
- the paramSpec
-
setParamSpec
public void setParamSpec(java.security.spec.AlgorithmParameterSpec paramSpec)Sets the paramSpec.- Parameters:
paramSpec- the paramSpec to set
-
loadParamSpec
Currently only default PBE spec.- Parameters:
config- configuration to load from- Returns:
- the param spec
-