title: PBKDF2WithHmacSHA1 key generation Takes too long on Android
body: <p>I want to generate key using PBKDF2WithHmacSHA1, but it takes too long to calculate on android. I am using same number of iteration on iOS with common crypto and it takes approximately 6 seconds where as on android it takes 100 seconds.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public static String generateStorngPasswordHash(String password)
  {
      try
      {
          char[] chars = password.toCharArray();
          byte[] salt = getSalt();
  
          PBEKeySpec spec = new PBEKeySpec(chars, salt, 1010101, 32 * 8);
          SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
          byte[] hash = skf.generateSecret(spec).getEncoded();
  
          return toHex(salt) + ":" + toHex(hash);
      } catch (Exception e)
      {
          Logger.e("Exception: Error in generating password" + e.toString());
      }
      return "";
  }
  
  private static byte[] getSalt() throws NoSuchAlgorithmException
  {
      SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
      byte[] salt = new byte[32];
      sr.nextBytes(salt);
      return salt;
  }
  </code></pre>
  
  <p>Please let me know if there is any problem with this code?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>One more thing, I am also using sqlCipher in my application. They use openssl for calculating PKDF2 and I have read somewhere that openssl implementation is very faster than java implementation to find PKDF2. So my question is:</p>
  
  <ol>
  <li>Is this true that openssl can give me better performace on android? </li>
  <li>Can I use openssl implementation used in sqlCipherg?</li>
  <li>If yes how can I use caclulate PKDF2 using openssl?</li>
  <li>If No then how can I use openssl to find <strong>PBKDF2WithHmacSHA1</strong> in android. I have<br>
  searched over the net but didn't found any example.</li>
  </ol>