Skip to content
Related Articles

Related Articles

KeyFactory getAlgorithm() method in Java with Examples
  • Last Updated : 04 Dec, 2018

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 program to demonstrate
// getAlgorithm()  method
  
import java.security.*;
import java.util.*;
import java.security.spec.*;
  
public class GFG1 {
    public static void main(String[] argv) throws Exception
    {
        try {
  
            // creating object of keyfactory
            KeyFactory keyFactory = KeyFactory.getInstance("DSA");
  
            // getting the algortihm of KeyFactory
            // using getAlgorithm() method
            String algo = keyFactory.getAlgorithm();
  
            // printing the algorithm
            System.out.println("Algortihm : " + algo);
        }
  
        catch (NoSuchAlgorithmException e) {
  
            System.out.println("Exception thrown : " + e);
        }
        catch (ProviderException e) {
  
            System.out.println("Exception thrown : " + e);
        }
    }
}


Output:

Algortihm : DSA

Example 2:




// Java program to demonstrate
// getAlgorithm()  method
  
import java.security.*;
import java.util.*;
import java.security.spec.*;
  
public class GFG1 {
    public static void main(String[] argv) throws Exception
    {
        try {
  
            // creating object of keyfactory
            KeyFactory keyFactory = KeyFactory
                                        .getInstance("DiffieHellman");
  
            // getting the algortihm of KeyFactory
            // using getAlgorithm() method
            String algo = keyFactory.getAlgorithm();
  
            // printing the algorithm
            System.out.println("Algortihm : " + algo);
        }
  
        catch (NoSuchAlgorithmException e) {
  
            System.out.println("Exception thrown : " + e);
        }
        catch (ProviderException e) {
  
            System.out.println("Exception thrown : " + e);
        }
    }
}


Output:

Algortihm : DiffieHellman

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :