Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Security

public final class Security
extends Object

java.lang.Object
   ↳ java.security.Security


Security is the central class in the Java Security API. It manages the list of security Provider that have been installed into this runtime environment.

Summary

Public methods

static int addProvider(Provider provider)

Adds the given provider to the collection of providers at the next available position.

static String getAlgorithmProperty(String algName, String propName)

This method was deprecated in API level 1. Use AlgorithmParameters and KeyFactory instead.

static Set<String> getAlgorithms(String serviceName)

Returns a Set of all registered algorithms for the specified cryptographic service.

static String getProperty(String key)

Returns the value of the security property named by the argument.

static Provider getProvider(String name)

Returns the Provider with the specified name.

static Provider[] getProviders(String filter)

Returns the array of providers which meet the user supplied string filter.

static Provider[] getProviders()

Returns an array containing all installed providers.

static Provider[] getProviders(Map<StringString> filter)

Returns the array of providers which meet the user supplied set of filters.

static int insertProviderAt(Provider provider, int position)

Insert the given Provider at the specified position.

static void removeProvider(String name)

Removes the Provider with the specified name form the collection of providers.

static void setProperty(String key, String value)

Sets the value of the specified security property.

Inherited methods

From class java.lang.Object

Public methods

addProvider

Added in API level 1
int addProvider (Provider provider)

Adds the given provider to the collection of providers at the next available position.

Parameters
provider Provider: the provider to be added.
Returns
int the actual position or -1 if the given provider was already in the list.

getAlgorithmProperty

Added in API level 1
String getAlgorithmProperty (String algName, 
                String propName)

This method was deprecated in API level 1.
Use AlgorithmParameters and KeyFactory instead.

Returns value for the specified algorithm with the specified name.

Parameters
algName String: the name of the algorithm.
propName String: the name of the property.
Returns
String value of the property.

getAlgorithms

Added in API level 1
Set<String> getAlgorithms (String serviceName)

Returns a Set of all registered algorithms for the specified cryptographic service. "Signature", "Cipher" and "KeyStore" are examples for such kind of services.

Parameters
serviceName String: the case-insensitive name of the service.
Returns
Set<String> a Set of all registered algorithms for the specified cryptographic service, or an empty Set if serviceName is null or if no registered provider provides the requested service.

getProperty

Added in API level 1
String getProperty (String key)

Returns the value of the security property named by the argument.

Parameters
key String: the name of the requested security property.
Returns
String the value of the security property.

getProvider

Added in API level 1
Provider getProvider (String name)

Returns the Provider with the specified name. Returns null if name is null or no provider with the specified name is installed.

Parameters
name String: the name of the requested provider.
Returns
Provider the provider with the specified name, maybe null.

getProviders

Added in API level 1
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 String: case-insensitive filter.
    Returns
    Provider[] the providers which meet the user supplied string filter filter. A null value signifies that none of the installed providers meets the filter specification.
    Throws
    InvalidParameterException if an unusable filter is supplied.
    NullPointerException if filter is null.
  • getProviders

    Added in API level 1
    Provider[] getProviders ()

    Returns an array containing all installed providers. The providers are ordered according their preference order.

    Returns
    Provider[] an array containing all installed providers.

    getProviders

    Added in API level 1
    Provider[] getProviders (Map<StringString> 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 Map: case-insensitive filter.
    Returns
    Provider[] the providers which meet the user supplied string filter filter. A null value signifies that none of the installed providers meets the filter specification.
    Throws
    InvalidParameterException if an unusable filter is supplied.
    NullPointerException if filter is null.
  • insertProviderAt

    Added in API level 1
    int insertProviderAt (Provider provider, 
                    int position)

    Insert the given Provider at the specified position. The positions define the preference order in which providers are searched for requested algorithms.

    Parameters
    provider Provider: the provider to insert.
    position int: the position (starting from 1).
    Returns
    int the actual position or -1 if the given provider was already in the list. The actual position may be different from the desired position.

    removeProvider

    Added in API level 1
    void removeProvider (String name)

    Removes the Provider with the specified name form the collection of providers. If the the Provider with the specified name is removed, all provider at a greater position are shifted down one position.

    Returns silently if name is null or no provider with the specified name is installed.

    Parameters
    name String: the name of the provider to remove.

    setProperty

    Added in API level 1
    void setProperty (String key, 
                    String value)

    Sets the value of the specified security property.

    Parameters
    key String
    value String
    This site uses cookies to store your preferences for site-specific language and display options.

    Hooray!

    This class requires API level or higher

    This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

    For more information about specifying the API level your app requires, read Supporting Different Platform Versions.