AlgorithmParameterGenerator getAlgorithm() 方法在 Java 中
可以使用 类 java.security.AlgorithmParameterGenerator 中的方法 getAlgorithm() 获取参数生成器的算法名称。此方法不需要任何参数,它以字符串形式返回算法名称。
演示此方法的程序如下所示 −
示例
import java.security.*;
import java.util.*;
public class Demo {
public static void main(String[] argv) {
try {
AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");
apGenerator.init(1024);
String algorithm = apGenerator.getAlgorithm();
System.out.println("The Algorithm is: " + algorithm);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
} catch (ProviderException e) {
System.out.println("Error!!! ProviderException");
}
}
}输出
The Algorithm is: DiffieHellman
现在让我们理解上述程序。
使用 getAlgorithm() 方法获取参数生成器的算法名称。然后显示此算法名称。如果算法名称错误,则会抛出异常 NoSuchAlgorithmException。演示的代码片段如下所示 −
try {
AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");
apGenerator.init(1024);
String algorithm = apGenerator.getAlgorithm();
System.out.println("The Algorithm is: " + algorithm);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
} catch (ProviderException e) {
System.out.println("Error!!! ProviderException");
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP