title: php openssl_pbkdf2 equivalent in java
body: <p>I have some php code to encrypt a message to webservice. Now, I want to create the equivalent java code but get stuck. Please help</p>
  
  <p>--PHP Code looks like</p>
  
  <pre><code>$length = 60;
  $salt =  "MySalt";
  $interation = 3000;
  $bytes = openssl_pbkdf2("mypasspharse", $salt, $length, $interation, "sha1");
  
  $value1 = substr($bytes, 0, 10);
  $value2 = substr($bytes, 10, 20);
  $value3 = substr($bytes, 30, 30);
  
  return array('value1' =&gt; $value1, 'value2' =&gt; $value2, 'value3' =&gt; $value3);
  </code></pre>
  
  <p>--</p>
  
  <p>I am trying to do the same thing in java using SecretKeyFactory. My java code looks like:</p>
  
  <pre><code>SecretKeyFactory factory = SecretKeyFactory
                  .getInstance("PBKDF2WithHmacSHA1");
          PBEKeySpec spec = new PBEKeySpec(passphrase.toCharArray(),
                  salt.getBytes("UTF-8"), interation, length);
  </code></pre>
  
  <p>Now I don't know how could I get the equivalent $value1, $value2, $value3 as php code. Also, Im not sure that I am doing the correct way to write the equivalent java code with the php code above. Any idea is very appreciated.</p>
  
  <p>Thank you,</p>