java.security.KeyFactory类的getProvider()方法用于获取此KeyFactory实例使用的提供程序对象的名称。
用法:
public final Provider getProvider()
参数:此方法不带任何参数。
返回值:此方法返回此KeyFactory实例使用的Provider对象的名称。
下面是说明getProvider()方法的示例:
示例1:
// Java program to demonstrate
// getProvider() method
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
{
try {
// creating object of keyfactory
KeyFactory keyFactory
= KeyFactory.getInstance("DSA");
// getting the Provider
// of the KeyFactory keyfactory
// by using method getProvider()
Provider provider
= keyFactory.getProvider();
// printing the provider name
System.out.println(
"Provider name: "
+ provider.getName());
}
catch (NoSuchAlgorithmException e) {
System.out.println(e);
}
}
}
输出:
Provider name: SUN
示例2:
// Java program to demonstrate
// getProvider() method
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
{
try {
// creating the object of KeyFactory
KeyFactory sr
= KeyFactory
.getInstance("DiffieHellman");
// getting the Provider of the KeyFactory sr
// by using method getProvider()
Provider provider = sr.getProvider();
// printing the provider name
System.out.println(
"Provider name: "
+ provider.getName());
}
catch (NoSuchAlgorithmException e) {
System.out.println(e);
}
}
}
输出:
Provider name: SunJCE