Provider.Service getType() method in Java with Examples
Last Updated :
19 Jan, 2023
The getType() method of java.security.Provider.Service class provides the type of the provider service.
Syntax:
public final String getType()
Return Value: This method provides specific type of provider service.
Below are the examples to illustrate the getType() method:
Example 1:
Java
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
{
try {
Signature sr
= Signature.getInstance(
"SHA1withDSA",
"SUN");
Provider provider = sr.getProvider();
Provider.Service service
= provider
.getService("Signature",
sr.getAlgorithm());
String name = service.getType();
System.out.println("Name of the type : "
+ name);
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
catch (NoSuchProviderException e) {
System.out.println("Exception thrown : " + e);
}
}
}
|
Output:
Name of the type : Signature
Example 2:
Java
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
{
try {
MessageDigest msd
= MessageDigest.getInstance("MD5");
Provider provider = msd.getProvider();
Provider.Service service
= provider
.getService("MessageDigest",
msd.getAlgorithm());
String name = service.getType();
System.out.println("Name of the type : "
+ name);
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
}
}
|
Output:
Name of the type : MessageDigest
Reference: https://docs.oracle.com/javase/9/docs/api/java/security/Provider.Service.html#getType–
Share your thoughts in the comments
Please Login to comment...