title: Does javax.crypto.KeyGenerator uses /random or /urandom to generate keys?
body: <p>Consider the following snippet where I use AES-256 to generate keys to encrypt - the thread which runs the following snippet gets blocked. I'm suspecting whether this could be due to the problem that sufficient entropy is not reached. So, that the thread could suspend (or) looks hanging till sufficient entropy is gathered by the system. </p>
  
  <p>I run this on a virtual machine and not on a physical one and I'm using Java8.</p>
  
  <p><strong>SNIPPET A</strong></p>
  
  <pre><code>KeyGenerator keyGen = KeyGenerator.getInstance("AES");
  keyGen.init(256);
  SecretKey key = keyGen.generateKey();
  </code></pre>
  
  <p>The following <a href="https://tersesystems.com/blog/2015/12/17/the-right-way-to-use-securerandom/" rel="nofollow noreferrer">article</a> infers that <code>SecureRandom</code> instance when obtained as </p>
  
  <pre><code>SecureRandom secureRandom = new SecureRandom();
  </code></pre>
  
  <p>The <code>NativePRNG</code> algorithm which is used by default to generate entropy is referred as <code>SHA1PRNG</code> which uses <code>/dev/urandom</code> by default and hence no thread blocking could occur.</p>
  
  <p>I'll come to the point why I'm speaking about these stuffs. The line</p>
  
  <pre><code>keyGen.init(256);
  </code></pre>
  
  <p>in the above snippet does the following action internally.</p>
  
  <pre><code> public final void init(int paramInt) {
       init(paramInt, JceSecurity.RANDOM);
   }
  </code></pre>
  
  <p>and what this <code>JceSecurity.RANDOM</code> has is this</p>
  
  <pre><code>static final SecureRandom RANDOM = new SecureRandom();
  </code></pre>
  
  <p>Means it should have used <a href="https://en.wikipedia.org/wiki//dev/random" rel="nofollow noreferrer"><code>/dev/urandom</code></a> and this shouldn't have blocked (or) hanged when the entropy is not gathered.</p>
  
  <p>I'm sharing my <a href="https://docs.zoho.com/download/4xwcw8f2b548be30641ccbe38c0a36cf18cbc" rel="nofollow noreferrer">java.security</a> file here.</p>
  
  <p>Can someone shed some insight on why the above thread which runs the <code>SNIPPET A</code> blocks?</p>