Java 中的 AlgorithmParameterGenerator getProvider() 方法
可以使用 java.security.AlgorithmParameterGenerator 类中的 getProvider() 方法获取生成器对象的供应商。此方法不需要参数,它返回生成器对象的供应商。
演示此方法的程序如下所示 -
示例
import java.security.*;
import java.util.*;
public class Demo {
public static void main(String[] argv) {
try {
AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");
apGenerator.init(1024);
Provider provider = apGenerator.getProvider();
System.out.println("The Provider is: " + provider);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
} catch (ProviderException e) {
System.out.println("Error!!! ProviderException");
}
}
}输出
The Provider is: SunJCE version 1.8
现在让我们来理解上述程序。
getProvider() 方法用于获取生成器对象的提供者。然后显示此提供者。如果算法名称错误,则会抛出异常 NoSuchAlgorithmException。演示代码片段如下所示 -
try {
AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");
apGenerator.init(1024);
Provider provider = apGenerator.getProvider();
System.out.println("The Provider is: " + provider);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
} catch (ProviderException e) {
System.out.println("Error!!! ProviderException");
}
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP