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 DefaultCryptingDelegateFactory INSTANCE  
  • Method Summary

    Modifier and Type Method Description
    protected void createCryptingDelegate()
    Creates and initializes the crypting delegate.
    java.lang.String getAlgorithm()
    Returns the algorithm.
    protected org.apache.commons.configuration.XMLConfiguration getConfiguration()
    Returns the configuration.
    ICryptingDelegate getCryptingDelegate()
    Returns a crypting delegate.
    protected java.lang.String getDelegateClassName()
    Returns the name of the delegate class.
    static ICryptingDelegateFactory getInstance()
    Returns the crypting delegate factory.
    protected java.lang.String getKeyAlias()
    Returns the public key alias in key store.
    java.security.KeyPair getKeyPair()
    Returns the keyPair.
    protected char[] getKeyPassword()
    Return the public key password
    protected byte[] getKeySalt()
    Return the public key salt.
    protected java.security.KeyStore getKeyStore()
    Returns the key store.
    protected org.apache.commons.configuration.SubnodeConfiguration getKeyStoreConfig()
    Returns the configuration for the keystore.
    protected char[] getKeyStorePassword()
    Return the key store password
    protected java.lang.String getKeyStorePath()
    Returns the key store path.
    protected java.lang.String getKeyStoreType()
    Returns the key store path.
    java.security.spec.AlgorithmParameterSpec getParamSpec()
    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 IPasswordCallback getPasswordCallback​(java.lang.String type)
    Returns a callback for the given type.
    protected org.apache.commons.configuration.SubnodeConfiguration getPasswordCallbackConfig​(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 void init()
    Initializes this factory.
    protected java.lang.String loadAlgorithm​(org.apache.commons.configuration.Configuration config)
    Returns the algorithm definition from the config
    protected java.security.spec.AlgorithmParameterSpec loadParamSpec​(org.apache.commons.configuration.Configuration config)
    Currently only default PBE spec.
    protected void loadSpec()
    Loads the spec params (lazily).
    void setAlgorithm​(java.lang.String algorithm)
    Sets the algorithm.
    void setKeyPair​(java.security.KeyPair keyPair)
    Sets the keyPair.
    void setParamSpec​(java.security.spec.AlgorithmParameterSpec paramSpec)
    Sets the paramSpec.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getInstance

      public static ICryptingDelegateFactory 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

      protected org.apache.commons.configuration.XMLConfiguration 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

      protected IPasswordCallback getPasswordCallback​(java.lang.String type)
      Returns a callback for the given type.
      Parameters:
      type - type of password callback
      Returns:
      the password callback
    • getPasswordCallbackConfig

      protected org.apache.commons.configuration.SubnodeConfiguration getPasswordCallbackConfig​(java.lang.String type)
      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:
      getSalt in interface ICryptingDelegateFactory
      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

      protected org.apache.commons.configuration.SubnodeConfiguration getKeyStoreConfig()
      Returns the configuration for the keystore.
      Returns:
      classname
    • getKeyStore

      protected java.security.KeyStore getKeyStore() throws java.io.IOException
      Returns 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:
      getPassphrase in interface ICryptingDelegateFactory
      Returns:
      passphrase
    • getCryptingDelegate

      public ICryptingDelegate getCryptingDelegate()
      Returns a crypting delegate.
      Specified by:
      getCryptingDelegate in interface ICryptingDelegateFactory
      Returns:
      a delegate
    • createCryptingDelegate

      protected void createCryptingDelegate()
      Creates and initializes the crypting delegate.
    • getKeyPair

      public java.security.KeyPair getKeyPair()
      Returns the keyPair.
      Specified by:
      getKeyPair in interface ICryptingDelegateFactory
      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:
      getAlgorithm in interface ICryptingDelegateFactory
      Returns:
      the algorithm
    • setAlgorithm

      public void setAlgorithm​(java.lang.String algorithm)
      Sets the algorithm.
      Parameters:
      algorithm - the algorithm to set
    • loadAlgorithm

      protected java.lang.String loadAlgorithm​(org.apache.commons.configuration.Configuration config)
      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:
      getParamSpec in interface ICryptingDelegateFactory
      Returns:
      the paramSpec
    • setParamSpec

      public void setParamSpec​(java.security.spec.AlgorithmParameterSpec paramSpec)
      Sets the paramSpec.
      Parameters:
      paramSpec - the paramSpec to set
    • loadParamSpec

      protected java.security.spec.AlgorithmParameterSpec loadParamSpec​(org.apache.commons.configuration.Configuration config)
      Currently only default PBE spec.
      Parameters:
      config - configuration to load from
      Returns:
      the param spec