KeyFactory getAlgorithm() method in Java with Examples
Last Updated :
24 Jun, 2021
The getAlgorithm() method of java.security.KeyFactory class is used to gets the name of the algorithm associated with this KeyFactory.
Syntax:
public final String getAlgorithm()
Return Value: This method returns the name of the algorithm associated with this KeyFactory.
Below are the examples to illustrate the getAlgorithm() method.
Example 1:
Java
import java.security.*;
import java.util.*;
import java.security.spec.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
try {
KeyFactory keyFactory = KeyFactory.getInstance( "DSA" );
String algo = keyFactory.getAlgorithm();
System.out.println( "Algorithm : " + algo);
}
catch (NoSuchAlgorithmException e) {
System.out.println( "Exception thrown : " + e);
}
catch (ProviderException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Example 2:
Java
import java.security.*;
import java.util.*;
import java.security.spec.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
try {
KeyFactory keyFactory = KeyFactory
.getInstance( "DiffieHellman" );
String algo = keyFactory.getAlgorithm();
System.out.println( "Algorithm : " + algo);
}
catch (NoSuchAlgorithmException e) {
System.out.println( "Exception thrown : " + e);
}
catch (ProviderException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output
Algorithm : DiffieHellman
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...