Java中的AlgorithmParameterGenerator getAlgorithm()方法
可以使用getAlgorithm()类java.security.AlgorithmParameterGenerator中的方法获得参数生成器的算法名称。此方法不需要任何参数,并且以字符串形式返回算法名称。
演示此的程序如下所示-
示例
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");
}热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短