Java中的 KeyFactory getAlgorithm() 方法及示例
Java.security.KeyFactory类的getAlgorithm( ) 方法用于获取与此KeyFactory 关联的算法的名称。
句法:
public final String getAlgorithm()
返回值:此方法返回与此 KeyFactory 关联的算法的名称。
下面是说明getAlgorithm()方法的示例。
示例 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);
}
}
}
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);
}
}
}
输出
Algorithm : DSA
示例 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);
}
}
}
输出
Algorithm : DiffieHellman