Windows JVM 级别上的 /dev/urandom 等价物是什么

pyd*_*oge 5 windows java jvm

最近因为熵的缺乏和阻塞rand IO导致挂起而遇到麻烦。在 Linux 上,我可以执行以下操作:

JAVA_OPTS=-Djava.security.egd=/dev/urandom ./myStartScript.sh
Run Code Online (Sandbox Code Playgroud)

Windows 上的等价物是什么?我们在 Linux 和 Windows 服务器上运行该应用程序,Linux 服务器使用 OpenJDK JRE,Windows 服务器使用 Oracle JRE。

我发现了很多关于 的建议CryptGenRandom,但是如何将其传递给 JVM 级别的应用程序?

小智 3

我在 jre/lib/security/java.security 中找到了文档证实了这一点。这是报价

选择“Sun”提供程序中“SHA1PRNG”和“NativePRNG”SecureRandom 实现的种子数据的主要来源。(其他 SecureRandom 实现也可能使用此属性。)

在类 Unix 系统(例如 Solaris/Linux/MacOS)上,“NativePRNG”和“SHA1PRNG”实现从特殊设备文件(例如 file:/dev/random)获取种子数据。

在 Windows 系统上,指定 URL“file:/dev/random”或“file:/dev/urandom”将为 SHA1PRNG 启用本机 Microsoft CryptoAPI 播种机制。

默认情况下,会尝试使用“securerandom.source”安全属性指定的熵收集设备。如果访问指定URL出现异常:

 SHA1PRNG:
     the traditional system/thread activity algorithm will be used.

 NativePRNG:
     a default value of /dev/random will be used.  If neither
     are available, the implementation will be disabled.
     "file" is the only currently supported protocol type.
Run Code Online (Sandbox Code Playgroud)