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

标签 java

方法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/

相关文章:

java - 实用程序员的练习 19

java - 导入证书出错?

java - 如何为 jar 文件生成校验和

java - JNDI - Glassfish JDBC,引用数据源时出错

java - 在 Java EE 6 中制作 Java Web 应用程序需要学习什么?

java - 如何使用 jackson 将具有 json 值的 Map<String, String> 转换为 POJO?

java - 发现索引越界异常

java - BadPaddingException 仅包含 "o"、 "b"、 "c"等字母

java - tomcat 服务器中 websphere 清除策略的等效属性

java - 覆盖 Java System.currentTimeMillis 以测试时间敏感代码