

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Provider getService() method in Java
The service that can describe the implementation of a Provider in regards to any algorithm is obtained using the method getService() in the class java.security.Provider. This method requires two parameters i.e. the service type required and the algorithm name of the required service.
A program that demonstrates this is given as follows −
Example
import java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) throws Exception { try { Signature sign = Signature.getInstance("SHA256withDSA"); Provider p = sign.getProvider(); Provider.Service s = p.getService("Signature", sign.getAlgorithm()); System.out.println("The Service for the Provider is: " + s); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }
Output
The Service for the Provider is: SUN: Signature.SHA256withDSA -> sun.security.provider.DSA$SHA256withDSA aliases: [OID.2.16.840.1.101.3.4.3.2, 2.16.840.1.101.3.4.3.2] attributes: {KeySize=2048, SupportedKeyClasses=java.security.interfaces.DSAPublicKey|java.security.interfaces.DSAPrivateKey}
Now let us understand the above program.
The getService() method is used to obtain the service that can describe the implementation of a Provider in regards to any algorithm. Then this is displayed. If the algorithm name is wrong, then the exception NoSuchAlgorithmException is thrown. A code snippet that demonstrates is given as follows −
try { Signature sign = Signature.getInstance("SHA256withDSA"); Provider p = sign.getProvider(); Provider.Service s = p.getService("Signature", sign.getAlgorithm()); System.out.println("The Service for the Provider is: " + s); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); }
- Related Questions & Answers
- Provider elements() method in Java
- Provider entrySet() method in Java
- Provider keys() method in Java
- Provider keySet() method in Java
- Provider values() method in Java
- Provider get() method in Java
- Provider getInfo() method in Java
- Provider getName() method in Java
- Provider getVersion() method in Java
- Provider toString() method in Java
- Provider getProperty() method in Java
- How can we create a Service Provider interface in Java 9?
- Using MDX provider in SAP HANA
- What are extender provider components in C#?
- Who is the best VoIP provider in the USA?
Advertisements