Class CryptoCipherFactory

java.lang.Object
org.apache.commons.crypto.cipher.CryptoCipherFactory

public class CryptoCipherFactory extends Object
Creates CryptoCipher instances.
  • Field Details

    • JCE_PROVIDER_KEY

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

      public static final 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:
    • AES_BLOCK_SIZE

      public static final int AES_BLOCK_SIZE
      For AES, the algorithm block is fixed size of 128 bits.
      See Also:
    • CLASSES_DEFAULT

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

    • CryptoCipherFactory

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

    • getCipherClassString

      private static String getCipherClassString(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(String transformation) throws 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:
      GeneralSecurityException - if JCE cipher initialize failed
    • getCryptoCipher

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