Java中的SecureRandom getProvider()方法
可以使用getProvider()类java.security.SecureRandom中的方法获得SecureRandom对象的提供程序。此方法不需要任何参数,它返回SecureRandom对象的提供程序。
演示此的程序如下所示-
示例
import java.security.*;
import java.util.*;
public class Demo {
public static void main(String[] argv) {
try {
SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");
Provider provider = sRandom.getProvider();
System.out.println("The Provider is: " + provider.getName());
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
}
}
}输出结果
The Provider is: SUN
现在让我们了解上面的程序。
该方法getProvider()用于获取SecureRandom对象的提供程序。然后显示此提供程序名称。如果算法名称错误,则会引发异常NoSuchAlgorithmException。演示的代码片段如下-
try {
SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");
Provider provider = sRandom.getProvider();
System.out.println("The Provider is: " + provider.getName());
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
}热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语