Package org.bouncycastle.crypto
Class CryptoServicesRegistrar
java.lang.Object
org.bouncycastle.crypto.CryptoServicesRegistrar
Basic registrar class for providing defaults for cryptography services in this module.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Available properties that can be set. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
Clear the global value for the passed in property.static <T> T[]
Clear the thread local value for the passed in property.static EntropySourceProvider
Return the default entropy source for this JVM.static NativeServices
static <T> T
getProperty
(CryptoServicesRegistrar.Property property) Return the default value for a particular property if one exists.static SecureRandom
Return the default source of randomness.static SecureRandom
getSecureRandom
(SecureRandom secureRandom) Return either the passed-in SecureRandom, or if it is null, then the default source of randomness.static SecureRandom
getSecureRandomIfSet
(SecureRandomProvider secureRandomProvider) If the default source of randomness is not set, return a SecureRandom generated from the passed in SecureRandomProvider.static <T> T[]
Return an array representing the current values for a sized property such as DH_DEFAULT_PARAMS or DSA_DEFAULT_PARAMS.static <T> T
getSizedProperty
(CryptoServicesRegistrar.Property property, int size) Return the value for a specific size for a sized property such as DH_DEFAULT_PARAMS or DSA_DEFAULT_PARAMS.static boolean
Return true or false depending on whether the current thread is in approved mode.static boolean
static boolean
setApprovedOnlyMode
(boolean isApprovedOnly) Set the calling thread's approved mode status.static <T> void
setGlobalProperty
(CryptoServicesRegistrar.Property property, T... propertyValue) Set the value of the the passed in property globally in the JVM.static void
setNativeEnabled
(boolean enabled) static void
setSecureRandom
(SecureRandom secureRandom) Set a default secure random to be used where none is otherwise provided.static void
setSecureRandomProvider
(SecureRandomProvider secureRandomProvider) Set a default secure random provider to be used where none is otherwise provided.static <T> void
setThreadProperty
(CryptoServicesRegistrar.Property property, T... propertyValue) Set the value of the the passed in property on the current thread only.
-
Field Details
-
MODULE_HMAC_KEY
- See Also:
-
-
Method Details
-
setApprovedOnlyMode
public static boolean setApprovedOnlyMode(boolean isApprovedOnly) Set the calling thread's approved mode status.Note: a thread cannot move to unapproved mode once it has moved into approved mode.
- Parameters:
isApprovedOnly
- true if should be approved mode, false otherwise.- Returns:
- true if the function has set the thread to approved mode, false otherwise.
-
isInApprovedOnlyMode
public static boolean isInApprovedOnlyMode()Return true or false depending on whether the current thread is in approved mode.- Returns:
- true if the current thread is in approved mode, false otherwise.
-
isNativeEnabled
public static boolean isNativeEnabled() -
setNativeEnabled
public static void setNativeEnabled(boolean enabled) -
getNativeServices
-
getSecureRandom
Return the default source of randomness.- Returns:
- the default SecureRandom
- Throws:
IllegalStateException
- if no source of randomness has been provided.
-
getSecureRandom
Return either the passed-in SecureRandom, or if it is null, then the default source of randomness.- Parameters:
secureRandom
- the SecureRandom to use if it is not null.- Returns:
- the SecureRandom parameter if it is not null, or else the default SecureRandom
-
getSecureRandomIfSet
If the default source of randomness is not set, return a SecureRandom generated from the passed in SecureRandomProvider.- Parameters:
secureRandomProvider
- the provider of SecureRandom to use if no default is provided.- Returns:
- a default SecureRandom, or one sourced from the provider if no default is available.
-
setSecureRandom
Set a default secure random to be used where none is otherwise provided.- Parameters:
secureRandom
- the SecureRandom to use as the default.
-
setSecureRandomProvider
Set a default secure random provider to be used where none is otherwise provided.- Parameters:
secureRandomProvider
- a provider SecureRandom to use when a default SecureRandom is requested.
-
getDefaultEntropySourceProvider
Return the default entropy source for this JVM.- Returns:
- the default entropy source.
-
getProperty
Return the default value for a particular property if one exists. The look up is done on the thread's local configuration first and then on the global configuration in no local configuration exists.- Type Parameters:
T
- the type to be returned- Parameters:
property
- the property to look up.- Returns:
- null if the property is not set, the default value otherwise,
-
getSizedProperty
Return an array representing the current values for a sized property such as DH_DEFAULT_PARAMS or DSA_DEFAULT_PARAMS.- Type Parameters:
T
- the base type of the array to be returned.- Parameters:
property
- the name of the property to look up.- Returns:
- null if the property is not set, an array of the current values otherwise.
-
getSizedProperty
Return the value for a specific size for a sized property such as DH_DEFAULT_PARAMS or DSA_DEFAULT_PARAMS.- Type Parameters:
T
- the type of the value to be returned.- Parameters:
property
- the name of the property to look up.size
- the size (in bits) of the defining value in the property type.- Returns:
- the current value for the size, null if there is no value set,
-
setThreadProperty
public static <T> void setThreadProperty(CryptoServicesRegistrar.Property property, T... propertyValue) Set the value of the the passed in property on the current thread only. More than one value can be passed in for a sized property. If more than one value is provided the first value in the argument list becomes the default value.- Type Parameters:
T
- the base type of the property value.- Parameters:
property
- the name of the property to set.propertyValue
- the values to assign to the property.
-
setGlobalProperty
public static <T> void setGlobalProperty(CryptoServicesRegistrar.Property property, T... propertyValue) Set the value of the the passed in property globally in the JVM. More than one value can be passed in for a sized property. If more than one value is provided the first value in the argument list becomes the default value.- Type Parameters:
T
- the base type of the property value.- Parameters:
property
- the name of the property to set.propertyValue
- the values to assign to the property.
-
clearGlobalProperty
Clear the global value for the passed in property.- Type Parameters:
T
- the base type of the property value- Parameters:
property
- the property to be cleared.- Returns:
- an array of T if a value was previously set, null otherwise.
-
clearThreadProperty
Clear the thread local value for the passed in property.- Type Parameters:
T
- the base type of the property value- Parameters:
property
- the property to be cleared.- Returns:
- an array of T if a value was previously set, null otherwise.
-