title: Java message digest update converted in php
body: <p>I have this code in Java <a href="https://pastebin.com/Z08w46ut" rel="nofollow noreferrer">Pastebin link</a>. Sorry for pastebin link but SO does allow me to paste that much code</p>
  
  <p>Which outputs "Ap1pAXP8yS"</p>
  
  <p>Im trying to convert the code in PHP . Till now I have converted some but its not working OK ( not getting Ap1pAXP8yS in PHP )  . </p>
  
  <p>The main problem seems to be the md.update </p>
  
  <p>Here the code in PHP </p>
  
  <pre><code>function bin2print($hex)
  {
      $out = "";
      $mapping = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '$', 'j', 'k', '-', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '=', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.', '/', '%' ];
      for ($i = 0; $i &lt; count($hex); $i++) {
  
          $j = $hex[$i];
  
          if ($j &lt; 0) {
              $j = 256 + $j;
          }
  
          $out.=  $mapping [($j % count($mapping)) ];
      }
      return $out;
  }
  
  function byteStr2byteArray($s)
  {
      return array_slice(unpack("C*", "\0".$s), 1);
  } 
  
  
  function getBytes($string)
  {
  
      $bytes = array();
      for($i = 0; $i &lt; strlen($string); $i++) {
          $bytes[] = ord($string[$i]);
      }
  
      $out = '';
      foreach($bytes as $single) {
          $out.=$single ;
      }
      return ($out);
  }
  
  $serial = '111111111111';
  $header = 'cow';
  
  $ctx = hash_init('md5' );
  hash_update($ctx, getBytes($header));
  hash_update($ctx, getBytes($serial));
  $raw = hash_final($ctx,true);
  
  $out = bin2print(byteStr2byteArray($raw));
  
  echo substr($out,0,10);
  </code></pre>
  
  <p>Wich outputs "-fjk7WCU2E"</p>
  
  <p>What im doing wrong ?</p>