title: Rfc2898DeriveBytes in java
body: <p>I am trying to implement the following code in java:</p>
  
  <pre><code>var keyGenerator = new Rfc2898DeriveBytes(password, salt, 1000);
  byte[] key = keyGenerator.GetBytes(32);
  byte[] iv = keyGenerator.GetBytes(16);
  using (AesManaged aes = new AesManaged())
  {
      using (ICryptoTransform encryptor = aes.CreateEncryptor(key, iv)) 
      {
          byte[] result = encryptor.TransformFinalBlock(content, 0, content.Length);
      }
  }
  </code></pre>
  
  <p>By using the following one:</p>
  
  <pre><code>SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
  PBEKeySpec keyspec = new PBEKeySpec(password, salt, 1000, 256);
  Key key = factory.generateSecret(keyspec);
  SecretKeySpec secret = new SecretKeySpec(key.getEncoded(), "AES");
  byte[] iv = "how_to_generate_in_java_as_in_c".getBytes();
  AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
  Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
  cipher.init(Cipher.ENCRYPT_MODE, secret, ivSpec);
  byte[] result = cipher.doFinal("asdfasdf".getBytes("UTF-8"));
  </code></pre>
  
  <p>I looked through a lot of examples and questions of SO and did not find a way to generate correctly iv[] (in the same value as in C). And it seems there is not way to do it, as java allow to create this value only as random (not pseudo random as available in C). Is this right?
  Could somebody please help with this issue?</p>