📌  相关文章
📜  Java中的 KeyPairGenerator getProvider() 方法及示例

📅  最后修改于: 2022-05-13 01:54:18.528000             🧑  作者: Mango

Java中的 KeyPairGenerator getProvider() 方法及示例

Java.security.KeyPairGenerator类的getProvider()方法用于返回此密钥对生成器对象的提供者。

句法:

public final Provider getProvider()

返回值:此方法返回此密钥对生成器对象的提供者。

以下是说明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 the object of KeyPairGenerator
            KeyPairGenerator sr = KeyPairGenerator
                                      .getInstance("RSA");
  
            // getting the Provider of the KeyPairGenerator 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("Exception thrown : " + e);
        }
    }
}
输出:
Provider name : SunRsaSign

示例 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 KeyPairGenerator
            KeyPairGenerator sr = KeyPairGenerator
                                      .getInstance("DiffieHellman");
  
            // getting the Provider of the KeyPairGenerator 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("Exception thrown : " + e);
        }
    }
}
输出:
Provider name : SunJCE