title: KeySpec throws "Salt not found" - Salt isn't a requirement
body: <p>I am currently working on a small bit of code, which is supposed to encrypt a byte[] before it gets stored inside a file. In the following snippet, I am trying to generate a SecretKey from a Password using PBKDF2.</p>
  
  <pre><code>public SecretKey deriveKey(String password)
          throws NoSuchAlgorithmException, InvalidKeySpecException {
      SecretKeyFactory kf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
      KeySpec specs = new PBEKeySpec(password.toCharArray());
      SecretKey key = kf.generateSecret(specs);
      return key;
  }
  </code></pre>
  
  <p>This throws an exception</p>
  
  <blockquote>
    <p>java.security.spec.InvalidKeySpecException: Salt not found</p>
  </blockquote>
  
  <p>at the last line before the return statement. This seems quite confusing to me as the PBEKeySpec does explicitly not require any more parameters as seen <a href="https://docs.oracle.com/javase/7/docs/api/javax/crypto/spec/PBEKeySpec.html#constructor_detail" rel="nofollow noreferrer">here</a>.</p>
  
  <p>This is not a tragedy, I was to add salt later anyway and it's even already defined further above but I was curious whether anybody knows why this happens. I might be doing something terribly wrong and just didn't notice.</p>