title: how to convert bytes MD5 in java to php
body: <p>How do I convert this Java code to PHP?</p>
  
  <pre><code>public static String encryptMD5_Salt(String content) {
      String resultString = "";
      String appkey = "acdf,kef";
  
      byte[] a = appkey.getBytes();
      byte[] datSource = content.getBytes();
      byte[] b = new byte[a.length + 4 + datSource.length];
  
      int i;
      for (i = 0; i &lt; datSource.length; i++) {
          b[i] = datSource[i];
      }
  
      b[i++] = (byte) 143;
      b[i++] = (byte) 112;
      b[i++] = (byte) 131;
      b[i++] = (byte) 143;
  
      for (int k = 0; k &lt; a.length; k++) {
          b[i] = a[k];
          i++;
      }
  
      try {
          MessageDigest md5 = MessageDigest.getInstance("MD5");
          md5.update(b);
          resultString = new HexBinaryAdapter().marshal(md5.digest());
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return resultString.toLowerCase();
  }
  </code></pre>
  
  <p>The problem is that I can't find the equivalent way to convert <code>Integer</code> to <code>byte</code> in java:</p>
  
  <pre><code>b[i++] = (byte) 143;
  b[i++] = (byte) 112;
  b[i++] = (byte) 131;
  b[i++] = (byte) 143;
  </code></pre>
  
  <p>the php codes:</p>
  
  <pre><code>$hexString = '123456';#sample value
  $bkey = pack('a*',$hexString);
  $bkey .= pack('N*',143,112,131,143);
  $bkey = pack('a*','acdf,kef');
  $re  = md5($bkey);
  $re =sha1('sha256',$re);
  </code></pre>
  
  <p>and they get difference result.</p>