Improving SecureRandom Performance in Java
When seeking cryptographically robust random numbers in Java, SecureRandom is the go-to solution. However, SecureRandom's performance can be sluggish, particularly when it relies on Linux's /dev/random, which might stall while gathering sufficient entropy.
To circumvent this performance penalty, consider adjusting the SecureRandom setup to employ the faster but slightly less secure /dev/urandom. This can be achieved by employing the following Java Virtual Machine (JVM) option:
-Djava.security.egd=file:/dev/urandom
However, this solution is not compatible with Java 5 and subsequent versions due to a known Java bug (6202721). To address this issue, use the following alternative JVM option:
-Djava.security.egd=file:/dev/./urandom
Note the inclusion of the additional "/./" path segment.
The above is the detailed content of How Can I Improve the Performance of Java's SecureRandom?. For more information, please follow other related articles on the PHP Chinese website!