title: Java 8 vs Python 2.7 pbkdf2 hashing -- different output hash letter casing
body: <p>I have written, previously in Python, a function to garble a target string using PBKDF2:</p>
  
  <pre><code>from hashlib import pbkdf2_hmac
  from binascii import hexlify
  
  def garbleString(string, salt, iterations, hash_algorithm):
      target = str.encode(string)
      dk = pbkdf2_hmac(hash_algorithm, target, salt, iterations)
      hash = hexlify(dk)
      return (hash, salt, iterations)
  
  &gt;&gt;&gt; garbleString("1000000000","salt",100000,'sha256')
  ('d973f4855206bd777b25355782f1b14bf06fb395bf49a26086035b3b8820a74b', 'salt',  100000)
  </code></pre>
  
  <p>Based on this page, this function is correct -- it yields the same hash for the same inputs. <a href="http://www.neurotechnics.com/tools/pbkdf2" rel="nofollow">http://www.neurotechnics.com/tools/pbkdf2</a></p>
  
  <p>I am now trying to implement the same in Java, here is where  I am now:</p>
  
  <pre><code>import java.security.NoSuchAlgorithmException;
  import java.security.spec.InvalidKeySpecException;
  import java.security.spec.KeySpec;
  import javax.crypto.spec.PBEKeySpec;
  import javax.crypto.SecretKey;
  import javax.crypto.SecretKeyFactory;
  import javax.xml.bind.DatatypeConverter;
  
  public class GarbledStringFactory {
  
      private String algorithm;
  
      public GarbledStringFactory(String algorithm){
          this.algorithm = algorithm;
      }
      public String getGarbledString(String string, String salt,  int iterations,  int derivedKeyLength) throws NoSuchAlgorithmException, InvalidKeySpecException {
          SecretKeyFactory f = SecretKeyFactory.getInstance(this.algorithm);
          KeySpec spec = new PBEKeySpec(string.toCharArray(), salt.getBytes(), iterations, derivedKeyLength * 8);
          SecretKey key = f.generateSecret(spec);
          String hexStr = DatatypeConverter.printHexBinary(key.getEncoded());
          return hexStr;
      }
  
      public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException {
          // TODO Auto-generated method stub
          GarbledStringFactory factory = new GarbledStringFactory("PBKDF2WithHmacSHA256");
          String hash = factory.getGarbledString("1000000000","salt",100000,32);
          System.out.println(hash);
      }
  }
  </code></pre>
  
  <p>This yields the hash "D973F4855206BD777B25355782F1B14BF06FB395BF49A26086035B3B8820A74B", which is the same, just with different letter casing. Does the casing matter?</p>