gpt4 book ai didi

java - SecureRandom.getInstanceStrong() 何时抛出 NoSuchAlgorithmException?

转载 作者:行者123 更新时间:2023-11-30 01:52:13 25 4
gpt4 key购买 nike

方法SecureRandom.getInstanceStrong()声明它可以抛出 NoSuchAlgorithmException,但是文档说:

Every implementation of the Java platform is required to support at least one strong SecureRandom implementation.

什么情况下会抛出这个异常?仅当属性 securerandom.strongAlgorithms 是用户定义且未列出算法时才会发生这种情况吗?

最佳答案

如果 securerandom.strongAlgorithms 配置不正确,似乎确实会引发此异常。未经检查的异常可能是更好的选择。

http://hg.openjdk.java.net/jdk/jdk/file/ac56154f0b9e/src/java.base/share/classes/java/security/SecureRandom.java

if (property == null || property.isEmpty()) {
throw new NoSuchAlgorithmException(
"Null/empty securerandom.strongAlgorithms Security Property");
}

...

throw new NoSuchAlgorithmException(
"No strong SecureRandom impls available: " + property);

关于java - SecureRandom.getInstanceStrong() 何时抛出 NoSuchAlgorithmException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55675003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com