Package org.apache.commons.crypto.random
Class CryptoRandomFactory
- java.lang.Object
-
- org.apache.commons.crypto.random.CryptoRandomFactory
-
public class CryptoRandomFactory extends java.lang.ObjectCreatesCryptoRandominstances
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCryptoRandomFactory.RandomProviderDefines the internal CryptoRandom implementations.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCLASSES_DEFAULTThe default value (OPENSSL,JAVA) used when creating aCryptoCipher.static java.lang.StringCLASSES_KEYThe configuration key of the CryptoRandom implementation class.static java.lang.StringDEVICE_FILE_PATH_DEFAULTThe default value ("/dev/urandom") of the file path for secure random device.static java.lang.StringDEVICE_FILE_PATH_KEYThe configuration key of the file path for secure random device.static java.lang.StringJAVA_ALGORITHM_DEFAULTThe default value ("SHA1PRNG") of the algorithm of secure random.static java.lang.StringJAVA_ALGORITHM_KEYThe configuration key of the algorithm of secure random.
-
Constructor Summary
Constructors Modifier Constructor Description privateCryptoRandomFactory()The private constructor ofCryptoRandomFactory.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CryptoRandomgetCryptoRandom()Gets a CryptoRandom instance using the default implementation as defined byCLASSES_DEFAULTstatic CryptoRandomgetCryptoRandom(java.util.Properties props)Gets a CryptoRandom instance for specified props.private static java.lang.StringgetRandomClassString(java.util.Properties props)Gets the CryptoRandom class.
-
-
-
Field Detail
-
DEVICE_FILE_PATH_KEY
public static final java.lang.String DEVICE_FILE_PATH_KEY
The configuration key of the file path for secure random device.- See Also:
- Constant Field Values
-
DEVICE_FILE_PATH_DEFAULT
public static final java.lang.String DEVICE_FILE_PATH_DEFAULT
The default value ("/dev/urandom") of the file path for secure random device.- See Also:
- Constant Field Values
-
JAVA_ALGORITHM_KEY
public static final java.lang.String JAVA_ALGORITHM_KEY
The configuration key of the algorithm of secure random.- See Also:
- Constant Field Values
-
JAVA_ALGORITHM_DEFAULT
public static final java.lang.String JAVA_ALGORITHM_DEFAULT
The default value ("SHA1PRNG") of the algorithm of secure random.- See Also:
- Constant Field Values
-
CLASSES_KEY
public static final java.lang.String CLASSES_KEY
The configuration key of the CryptoRandom implementation class.The value of the CLASSES_KEY needs to be the full name of a class that implements the
CryptoRandominterface The internal classes are listed in the enumRandomProviderwhich 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,JAVA) used when creating aCryptoCipher.
-
-
Constructor Detail
-
CryptoRandomFactory
private CryptoRandomFactory()
The private constructor ofCryptoRandomFactory.
-
-
Method Detail
-
getCryptoRandom
public static CryptoRandom getCryptoRandom() throws java.security.GeneralSecurityException
Gets a CryptoRandom instance using the default implementation as defined byCLASSES_DEFAULT- Returns:
- CryptoRandom the cryptoRandom object.
- Throws:
java.security.GeneralSecurityException- if cannot create theCryptoRandomclass
-
getCryptoRandom
public static CryptoRandom getCryptoRandom(java.util.Properties props) throws java.security.GeneralSecurityException
Gets a CryptoRandom instance for specified props. Uses the SECURE_RANDOM_CLASSES_KEY from the provided properties. If it is not set, then it checks the System properties. Failing that, it defaults to OpenSslCryptoRandom,JavaCryptoRandom The properties are passed to the generated class.- Parameters:
props- the configuration properties.- Returns:
- CryptoRandom the cryptoRandom object.
- Throws:
java.security.GeneralSecurityException- if cannot create theCryptoRandomclassjava.lang.IllegalArgumentException- if no classname(s) are provided
-
getRandomClassString
private static java.lang.String getRandomClassString(java.util.Properties props)
Gets the CryptoRandom class.- Parameters:
props- ThePropertiesclass represents a set of properties.- Returns:
- the CryptoRandom class based on the props.
-
-