Package java.security
Class Security
- java.lang.Object
-
- java.security.Security
-
public final class Security extends Object
Securityis the central class in the Java Security API. It manages the list of securityProviderthat have been installed into this runtime environment.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intaddProvider(Provider provider)Adds the givenproviderto the collection of providers at the next available position.static StringgetAlgorithmProperty(String algName, String propName)Deprecated.UseAlgorithmParametersandKeyFactoryinstead.static Set<String>getAlgorithms(String serviceName)Returns aSetof all registered algorithms for the specified cryptographic service.static StringgetProperty(String key)Returns the value of the security property named by the argument.static ProvidergetProvider(String name)Returns theProviderwith the specified name.static Provider[]getProviders()Returns an array containing all installed providers.static Provider[]getProviders(String filter)Returns the array of providers which meet the user supplied string filter.static Provider[]getProviders(Map<String,String> filter)Returns the array of providers which meet the user supplied set of filters.static intinsertProviderAt(Provider provider, int position)Insert the givenProviderat the specifiedposition.static voidremoveProvider(String name)Removes theProviderwith the specified name form the collection of providers.static voidsetProperty(String key, String value)Sets the value of the specified security property.
-
-
-
Method Detail
-
getAlgorithmProperty
@Deprecated public static String getAlgorithmProperty(String algName, String propName)
Deprecated.UseAlgorithmParametersandKeyFactoryinstead.Returns value for the specified algorithm with the specified name.- Parameters:
algName- the name of the algorithm.propName- the name of the property.- Returns:
- value of the property.
-
insertProviderAt
public static int insertProviderAt(Provider provider, int position)
Insert the givenProviderat the specifiedposition. The positions define the preference order in which providers are searched for requested algorithms.- Parameters:
provider- the provider to insert.position- the position (starting from 1).- Returns:
- the actual position or
-1if the givenproviderwas already in the list. The actual position may be different from the desired position.
-
addProvider
public static int addProvider(Provider provider)
Adds the givenproviderto the collection of providers at the next available position.- Parameters:
provider- the provider to be added.- Returns:
- the actual position or
-1if the givenproviderwas already in the list.
-
removeProvider
public static void removeProvider(String name)
Removes theProviderwith the specified name form the collection of providers. If the theProviderwith the specified name is removed, all provider at a greater position are shifted down one position.Returns silently if
nameisnullor no provider with the specified name is installed.- Parameters:
name- the name of the provider to remove.
-
getProviders
public static Provider[] getProviders()
Returns an array containing all installed providers. The providers are ordered according their preference order.- Returns:
- an array containing all installed providers.
-
getProvider
public static Provider getProvider(String name)
Returns theProviderwith the specified name. Returnsnullif name isnullor no provider with the specified name is installed.- Parameters:
name- the name of the requested provider.- Returns:
- the provider with the specified name, maybe
null.
-
getProviders
public static Provider[] getProviders(String filter)
Returns the array of providers which meet the user supplied string filter. The specified filter must be supplied in one of two formats:- CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE
(for example: "MessageDigest.SHA")
- CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE ATTR_NAME:ATTR_VALUE
(for example: "Signature.MD2withRSA KeySize:512")
- Parameters:
filter- case-insensitive filter.- Returns:
- the providers which meet the user supplied string filter
filter. Anullvalue signifies that none of the installed providers meets the filter specification. - Throws:
InvalidParameterException- if an unusable filter is supplied.NullPointerException- iffilterisnull.
- CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE
-
getProviders
public static Provider[] getProviders(Map<String,String> filter)
Returns the array of providers which meet the user supplied set of filters. The filter must be supplied in one of two formats:- CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE
for example: "MessageDigest.SHA" The value associated with the key must be an empty string.
- CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE ATTR_NAME:ATTR_VALUE
for example: "Signature.MD2withRSA KeySize:512" where "KeySize:512" is the value of the filter map entry.
- Parameters:
filter- case-insensitive filter.- Returns:
- the providers which meet the user supplied string filter
filter. Anullvalue signifies that none of the installed providers meets the filter specification. - Throws:
InvalidParameterException- if an unusable filter is supplied.NullPointerException- iffilterisnull.
- CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE
-
getProperty
public static String getProperty(String key)
Returns the value of the security property named by the argument.- Parameters:
key- the name of the requested security property.- Returns:
- the value of the security property.
-
setProperty
public static void setProperty(String key, String value)
Sets the value of the specified security property.
-
getAlgorithms
public static Set<String> getAlgorithms(String serviceName)
Returns aSetof all registered algorithms for the specified cryptographic service."Signature","Cipher"and"KeyStore"are examples for such kind of services.- Parameters:
serviceName- the case-insensitive name of the service.- Returns:
- a
Setof all registered algorithms for the specified cryptographic service, or an emptySetifserviceNameisnullor if no registered provider provides the requested service.
-
-