我一直在试验用于 Java 的 BouncyCaSTLe API,并慢慢地阅读他们的“Java 密码学 - 工具和技术”电子书。这本书包含一个名为“关于熵的词”的简短部分,其中陈述了以下内容:
What the JVM is using as an entropy source will vary, on Linux for example, it is normally set to “/dev/random” which may block. Usually installing “rng-tools” or the nearest equivalent will deal with this as it will also expose any underlying hardware supporting RNG generation to be used for seeding “/dev/random”. With some virtual environments hardware RNG may never be available, in that case it is important to find other ways of making entropy available to your JVM. Ways of doing this will vary with the environment you are using.
我可能误解了这段摘录的意思,但我如何才能使熵对 JVM 可用呢?除了声明“执行此操作的方法将因您使用的环境而异”之外,该书对此并没有特别具体的说明。是否有某种我不知道的熵 SPI 可用于为 JVM 提供熵源?我的问题不是如何生成熵或从 JVM 中检索它,而是如果我已经知道并可以访问可靠的熵源(例如随机位文件),我该如何制作这个熵源JVM 是否可用,以便在其他安全熵源不可用的情况下,它可以用于播种?
最佳答案
这可能因 JVM 供应商而异,但根据
Avoiding JVM Delays Caused by Random Number Generation对于 Sun/Oracle JVM,可以在 $JAVA_HOME/jre/lib/security/java.security
文件中设置 securerandom.source
属性。这允许改变熵的来源,例如从 /dev/random
到 /dev/urandom
。
要添加更多熵,可以简单地写入 /dev/random
。根据 this answer这可能不安全但是:
It is also possible to write to /dev/random. This allows any user to mix random data into the pool.
关于java - 为 JVM 提供熵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820576/