Saturday, June 20, 2026
HomeLanguagesJavaKeyFactory getAlgorithm() method in Java with Examples

KeyFactory getAlgorithm() method in Java with Examples

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




// 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 algorithm of KeyFactory
            // using getAlgorithm() method
            String algo = keyFactory.getAlgorithm();
 
            // printing the algorithm
            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 : DSA

Example 2: 
 

Java




// 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 algorithm of KeyFactory
            // using getAlgorithm() method
            String algo = keyFactory.getAlgorithm();
 
            // printing the algorithm
            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
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6899 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS