title: KeyStore get key without password
body: <p>I need to know if its possible to retrieve a key from a KeyStore without providing the 'storepass'. The documentation <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/keytool.html#OptionsInAll" rel="nofollow">here </a>says that <em>"When retrieving information from the keystore, the password is optional; if no password is given, the integrity of the retrieved information cannot be checked and a warning is displayed"</em></p>
  
  <p>However when I try to get the Key without a password I get <em>"java.lang.IllegalArgumentException: password can't be null"</em> exception.</p>
  
  <p>Following is how I created the KeyStore</p>
  
  <blockquote>
    <p>keytool -genseckey -alias "myKey" -keystore KEYSTORE.jks -storepass "password" -storetype "JCEKS" -keyalg AES -keysize 128</p>
  </blockquote>
  
  <p>And I tried to retrieve it as follows</p>
  
  <pre><code>final KeyStore keyStore = KeyStore.getInstance("JCEKS");
  keyStore.load(new FileInputStream(new File("C:\\temp\\keytool\\KEYSTORE.jks")), 
    null);
  final Key key = keyStore.getKey("myKey", null);
  </code></pre>
  
  <p>Which throws the following exception</p>
  
  <pre><code>java.lang.IllegalArgumentException: password can't be null
  at com.sun.crypto.provider.SunJCE_z.&lt;init&gt;(DashoA13*..)
  at com.sun.crypto.provider.JceKeyStore.engineGetKey(DashoA13*..)
  at java.security.KeyStore.getKey(KeyStore.java:763)
  </code></pre>
  
  <p>Have I misunderstood the documentation completely? Is there any other way around this, as I don't see the point in storing the 'storepass' in clear in my code where everyone can see it, therefore making the password useless.</p>