title: PBKDF2WithHmacSHA1 Java to Swift 3
body: <p>I would like to hash a password in swift 3 using the same algorithm(PBKDF2WithHmacSHA1) in Java</p>
  
  <p>Here is code in Java: </p>
  
  <pre><code>char[] passwordChars = password.toCharArray();
  byte[] saltBytes = Constantes.SALT.getBytes();
  PBEKeySpec spec = new PBEKeySpec(passwordChars, saltBytes, Constantes.ITERATIONS,192);
  
  try {
      SecretKeyFactory  key = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
      byte[] hashedPassword = key.generateSecret(spec).getEncoded();   
      return String.format("%x", new BigInteger(hashedPassword));
  } catch {[..]}
  </code></pre>
  
  <p>result example for keyword "test" : 2d21d1a136b22280a47499789ae4bedfb63ce900e97064</p>
  
  <p>I tried to use CryptoSwift like this:</p>
  
  <pre><code>let passwordArray: [UInt8] = Array(test.utf8)
  let saltArray: [UInt8] = Array(salt.utf8)
  
  let result = try! PKCS5.PBKDF2(password: passwordArray, salt: saltArray, iterations: iter, keyLength: 192, variant: .sha1).calculate()
  </code></pre>
  
  <p>result: </p>
  
  <blockquote>
    <p>b35a9b2a6150373b5cf81a7a616bc80f8cbe9ec25eac9b111798feb9e2fa9b1c0aa4627d0fb6c1820d2a5b432b1dd688a06692f3a8e2b2136d8c03f26d28de49bdfe4ecb76821ee4e74139f2580361405b788eab0d35d339a91dedaa566ec13d96f8c812a5ccb84a8e923fad7c9a4ecf7eaced67a37b66fb062c8043e4125c2fb68cc2f3ebe0374087b72ac8e15146e24d239ee2577fd1ef581f3ae9b7dd5d16681da114a04f182586b63ff1388e63cea96212574817426a1cd1d35dd2c22e1a</p>
  </blockquote>
  
  <p>I note that the result is not the same, </p>
  
  <p>Do you have any idea where the problem may come from?</p>