title: Java - repetitive hmacSHA1 hashing - how to convert to PHP?
body: <p>How do you convert the following Java to PHP?</p>
  
  <pre><code>byte[] byteArray1 = key1.getBytes("UTF8");
  byte[] byteArray2 = key2.getBytes("UTF8");
  byte[] byteArray3 = key3.getBytes("UTF8");
  byte[] byteArray4 = key4.getBytes("UTF8");
  
  Mac mac = Mac.getInstance("HmacSHA1");
  SecretKeySpec derivedKey = new SecretKeySpec(byteArray1, "HmacSha1");
  mac.init(derivedKey); derivedKey = new SecretKeySpec(mac.doFinal(byteArray2), "HmacSha1"); }
  mac.init(derivedKey); derivedKey = new SecretKeySpec(mac.doFinal(byteArray3), "HmacSha1");
  mac.init(derivedKey); derivedKey = new SecretKeySpec(mac.doFinal(byteArray4), "HmacSha1");
  </code></pre>
  
  <p>From all the research I've done, it looks like <strong>if we'd remove the last two lines</strong>, we could neatly convert it to PHP as follows:</p>
  
  <pre><code>hash_hmac("sha1", $key2, $key1, true);
  </code></pre>
  
  <p><strong>However, how to you convert this type of reiterative hashing to PHP?</strong></p>
  
  <p><em>Note: I've tried the following unsuccessfully:</em></p>
  
  <pre><code>$derivedKey = hash_hmac("sha1", $key2, $key1, true);
  $derivedKey = hash_hmac("sha1", $key3, $derivedKey, true);
  $derivedKey = hash_hmac("sha1", $key4, $derivedKey, true);  
  </code></pre>