Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I translate this C# code into PHP?
    text
    copied!<p>I need a PHP version of the following C# code:</p> <pre><code>string dateSince = "2010-02-01"; string siteID = "bash.org"; string sharedSecret = "12345"; // the same combination on my luggage! using System.Security.Cryptography; MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); byte[] dataBytes = System.Text.Encoding.ASCII.GetBytes(string.Format("{0}{1}{2}", dateSince, siteID, sharedSecret)); string result = BitConverter.ToString(x.ComputeHash(dataBytes)); </code></pre> <p>... this code snippet appears to be incomplete. But here's what I think is going on:</p> <ol> <li><p>concatenating dateSince, siteID, and sharedSecret. Stealing underpants.</p></li> <li><p>???</p></li> <li><p>converting that string into a ascii encoded byte array.</p></li> <li><p>taking the MD5 hash of that array.</p></li> </ol> <p>This mysterious BitConverter object appears to be converting that MD5 hashed array, into a string of hexadecimal numbers. According to the aforementioned doc, the value of result should look something like: "6D-E9-9A-B6-73-D8-10-79-BC-4F-EE-51-A4-84-15-D8"</p> <p>Any help is greatly appreciated!!</p> <hr> <p>Forgot to include this earlier. Here's the PHP version of what I've written so far:</p> <pre><code>$date_since = "2010-02-01"; $site_id = "bash.org"; $shared_secret = "12345"; $initial_token = $date_since.$site_id.$shared_secret; $ascii_version = array(); foreach($i=0; $i &lt; strlen($initial_token); $i++) { $ascii_version[] = ord(substr($initial_token,$i,1)); } $md5_version = md5(join("", $ascii_version)); $hexadecimal_bits = array(); foreach($i=0; $i &lt; strlen($md5_version); $i++) { // @todo convert to hexadecimal here? $hexadecimal_bits[] = bin2hex(substr($md5_version,$i,1)); } $result = join("-", $hexadecimal_bits); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload