JEP-123 で利用時に指定する方法が提案されてJava8で使えるようになったらしい。Linuxだと標準で /dev/random を使うからエントロピーが全部消費されてる状態だとブロックされてた。
- http://openjdk.java.net/jeps/123
- https://bugs.openjdk.java.net/browse/JDK-8046113
- http://docs.oracle.com/javase/jp/8/technotes/guides/security/StandardNames.html#SecureRandom
- http://docs.oracle.com/javase/jp/7/technotes/guides/security/StandardNames.html#SecureRandom
- http://docs.oracle.com/javase/jp/8/api/java/security/SecureRandom.html#getInstance-java.lang.String-java.lang.String-
- http://docs.oracle.com/javase/jp/8/api/java/security/Security.html#getProvider-java.lang.String-
- http://blog.64p.org/entry/2014/10/08/233604
SecureRandom を作るときに NativePRNGNonBlocking を使う
SecureRandom.getInstance("NativePRNGNonBlocking")Java8から強い乱数生成器を使うには SecureRandom.getInstanceStrong() が推奨されてるっぽい。
System.out.println(new SecureRandom().getAlgorithm());
System.out.println(SecureRandom.getInstanceStrong().getAlgorithm());NativePRNG
NativePRNGBlocking
http://stackoverflow.com/questions/137212/how-to-solve-performance-problem-with-java-securerandom
a. java.security.egd に urandom を指定する
java -Djava.security.egd=file:/dev/./urandomb. SecureRandom を作るときに SHA1PRNG を使う (Windows の場合と同じ動作)
SecureRandom.getInstance("SHA1PRNG")というか、1.7.0_71 で java.security に urandom 指定されてるし random 指定すると SHA1PRNG が使われるんですが??
いろいろ勘違いしてた。
- Java7の場合
securerandom.sourceのデフォルト値は/dev/urandomになっているsecurerandom.sourceに/dev/urandomが指定されているとデフォルトのアルゴリズムとしてNativePRNGが使われる- 乱数生成器は
/dev/urandomが使われる
- 乱数生成器は
securerandom.sourceに/dev/randomが指定されているとデフォルトのアルゴリズムとしてSHA1PRNGが使われる- 乱数生成器はJavaで作られたものを使う
- この時乱数の種を
java.security.egdで指定されたデバイスから取得する- 乱数の種はおそらくJavaの起動時に一度だけ取得される (もしくは
SecureRandomを作った時) java.security.egdのデフォルトは/dev/randomになっているから、何度も実行するとブロックすることがあるjava.security.egdに/dev/urandomを指定すると種も擬似乱数になるからブロックしない
- 乱数の種はおそらくJavaの起動時に一度だけ取得される (もしくは
- Java8
securerandom.sourceのデフォルト値は/dev/randomになっているsecurerandom.sourceが/dev/randomでも/dev/urandomでもデフォルトのアルゴリズムとしてNativePRNGが使われる- 乱数生成器は
/dev/randomな気がするけど自身ない
- 乱数生成器は
getInstanceStrongを指定した場合はNativePRNGBlockingがアルゴリズムとして使われる- 乱数生成器は
/dev/randomが使われる
- 乱数生成器は
ソース見て確認しよう。