Class CryptoCipherFactory


  • public class CryptoCipherFactory
    extends java.lang.Object
    Creates CryptoCipher instances.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CryptoCipherFactory.CipherProvider
      Defines the internal CryptoCipher implementations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AES_BLOCK_SIZE
      For AES, the algorithm block is fixed size of 128 bits.
      private static java.lang.String CLASSES_DEFAULT
      The default value (OPENSSL,JCE) for crypto cipher.
      static java.lang.String CLASSES_KEY
      The configuration key of the CryptoCipher implementation class.
      static java.lang.String JCE_PROVIDER_KEY
      The configuration key of the provider class for JCE cipher.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String getCipherClassString​(java.util.Properties props)
      Gets the cipher class.
      static CryptoCipher getCryptoCipher​(java.lang.String transformation)
      Gets a cipher for algorithm/mode/padding in config value commons.crypto.cipher.transformation
      static CryptoCipher getCryptoCipher​(java.lang.String transformation, java.util.Properties properties)
      Gets a cipher instance for specified algorithm/mode/padding.
      • Methods inherited from class java.lang.Object

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

      • JCE_PROVIDER_KEY

        public static final java.lang.String JCE_PROVIDER_KEY
        The configuration key of the provider class for JCE cipher.
        See Also:
        Constant Field Values
      • CLASSES_KEY

        public static final java.lang.String CLASSES_KEY
        The configuration key of the CryptoCipher implementation class.

        The value of CLASSES_KEY needs to be the full name of a class that implements the CryptoCipher interface The internal classes are listed in the enum CipherProvider which can be used to obtain the full class name.

        The value can also be a comma-separated list of class names in order of descending priority.

        See Also:
        Constant Field Values
      • CLASSES_DEFAULT

        private static final java.lang.String CLASSES_DEFAULT
        The default value (OPENSSL,JCE) for crypto cipher.
    • Constructor Detail

      • CryptoCipherFactory

        private CryptoCipherFactory()
        The private Constructor of CryptoCipherFactory.
    • Method Detail

      • getCipherClassString

        private static java.lang.String getCipherClassString​(java.util.Properties props)
        Gets the cipher class.
        Parameters:
        props - The Properties class represents a set of properties.
        Returns:
        the cipher class based on the props.
      • getCryptoCipher

        public static CryptoCipher getCryptoCipher​(java.lang.String transformation)
                                            throws java.security.GeneralSecurityException
        Gets a cipher for algorithm/mode/padding in config value commons.crypto.cipher.transformation
        Parameters:
        transformation - the name of the transformation, e.g., AES/CBC/PKCS5Padding. See the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard transformation names.
        Returns:
        CryptoCipher the cipher object (defaults to OpenSslCipher if available, else JceCipher)
        Throws:
        java.security.GeneralSecurityException - if JCE cipher initialize failed
      • getCryptoCipher

        public static CryptoCipher getCryptoCipher​(java.lang.String transformation,
                                                   java.util.Properties properties)
                                            throws java.security.GeneralSecurityException
        Gets a cipher instance for specified algorithm/mode/padding.
        Parameters:
        properties - the configuration properties - uses CLASSES_KEY
        transformation - algorithm/mode/padding
        Returns:
        CryptoCipher the cipher (defaults to OpenSslCipher)
        Throws:
        java.security.GeneralSecurityException - if cipher initialize failed
        java.lang.IllegalArgumentException - if no classname(s) were provided