java.security.KeyPairGenerator类的getAlgorithm()方法用于返回此 key 对生成器的算法的标准名称。有关标准算法名称的信息,请参见Java密码体系结构标准算法名称文档中的KeyPairGenerator部分。
用法:
public String getAlgorithm()
返回值:此方法返回算法的标准字符串名称。
以下示例说明了getAlgorithm()方法
示例1:
// Java program to demonstrate
// genKeyPair() method
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
try {
// creating the object of KeyPairGenerator
KeyPairGenerator kpg = KeyPairGenerator
.getInstance("RSA");
// fetching the Algorithm
// using getAlgorithm() method
String algo = kpg.getAlgorithm();
// pritning the string algo
System.out.println("Algorithm : " + algo);
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
}
}
输出:
Algorithm : RSA
示例2:
// Java program to demonstrate
// genKeyPair() method
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
try {
// creating the object of KeyPairGenerator
KeyPairGenerator kpg = KeyPairGenerator
.getInstance("DiffieHellman");
// fetching the Algorithm
// using getAlgorithm() method
String algo = kpg.getAlgorithm();
// pritning the string algo
System.out.println("Algorithm : " + algo);
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
}
}
输出:
Algorithm : DiffieHellman