getService( String type, String algorithm)
The
getService() method of
java.security.Provider class is used to get the service describing this Provider's implementation of the specified type of this algorithm or alias.
If no such implementation exists, this method returns null. If there are two matching services, one added to this provider using putService() and one added via put(), the service added via putService() is returned.
Syntax:
public Provider.Service getService(String type, String algorithm)
Parameters: This method takes the following argument as a parameter.
- type- the type of service requested.
- algorithm- the case insensitive algorithm name (or alternate alias) of the service requested.
Return Value: This method returns the
service describing this Provider's matching service or
null if no such service exists.
Exception: This method throws
NullPointerException if type or algorithm is null.
Below are the examples to illustrate the
getService() method:
Example 1:
Output:
Provider service : SUN: Signature.SHA1withDSA -> sun.security.provider.DSA$SHA1withDSA
aliases: [DSA, DSS, SHA/DSA, SHA-1/DSA, SHA1/DSA, SHAwithDSA, DSAWithSHA1, OID.1.2.840.10040.4.3, 1.2.840.10040.4.3, 1.3.14.3.2.13, 1.3.14.3.2.27]
attributes: {ImplementedIn=Software, KeySize=1024, SupportedKeyClasses=java.security.interfaces.DSAPublicKey|java.security.interfaces.DSAPrivateKey}
Example 2: To show NullPointerException thrown by getService() method.
Output:
Exception thrown : java.lang.NullPointerException
getServices()
The
getServices() method of
java.security.Provider class is used to get an unmodifiable Set of all services supported by this Provider.
Syntax:
public Set<Provider.Service> getServices()
Return Value: This method returns an
unmodifiable Set of all services supported by this Provider.
Below are the examples to illustrate the getServices() method:
Program 1:
Output:
Provider servicelist :
Value is : SUN: SecureRandom.NativePRNG -> sun.security.provider.NativePRNG
Value is : SUN: SecureRandom.SHA1PRNG -> sun.security.provider.SecureRandom
attributes: {ImplementedIn=Software}
Value is : SUN: SecureRandom.NativePRNGBlocking -> sun.security.provider.NativePRNG$Blocking
Value is : SUN: SecureRandom.NativePRNGNonBlocking -> sun.security.provider.NativePRNG$NonBlocking
Value is : SUN: Signature.SHA1withDSA -> sun.security.provider.DSA$SHA1withDSA
aliases: [DSA, DSS, SHA/DSA, SHA-1/DSA, SHA1/DSA, SHAwithDSA, DSAWithSHA1, OID.1.2.840.10040.4.3, 1.2.840.10040.4.3, 1.3.14.3.2.13, 1.3.14.3.2.27]
attributes: {ImplementedIn=Software, KeySize=1024, SupportedKeyClasses=java.security.interfaces.DSAPublicKey|java.security.interfaces.DSAPrivateKey}