我需要下面的C#代碼的PHP版本:如何將此C#代碼轉換爲PHP?
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));
...這個代碼片段似乎是不完整的。但這是我的想法:
concatenating dateSince,siteID和sharedSecret。偷內褲。
???
將該字符串轉換爲ascii編碼的字節數組。
獲取該數組的MD5散列值。
這個神祕的BitConverter對象似乎是將該MD5散列數組轉換爲一串十六進制數字。根據上述文件,結果的值應該如下所示:「6D-E9-9A-B6-73-D8-10-79-BC-4F-EE-51-A4-84-15-D8」
任何幫助非常感謝!
忘記包含此更早。這裏是我寫到目前爲止的PHP版本:
$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 < 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 < strlen($md5_version); $i++) {
// @todo convert to hexadecimal here?
$hexadecimal_bits[] = bin2hex(substr($md5_version,$i,1));
}
$result = join("-", $hexadecimal_bits);
請發佈您迄今爲止編寫的代碼。人們通常不喜歡只爲你寫代碼。 – 2010-02-03 01:35:06
啊,對不起,我剛來這地方。一會兒......。 – sayajay 2010-02-03 01:46:04
+1與您的行李一樣。 – benjy 2010-02-03 02:27:02