私はこのC#のコードがあります:あなたはonline versionの.asを見ることができます。ここC#コードPHP同等のmd5ハッシュ
public static string Encript(string strData)
{
string hashValue = HashData(strData);
string hexHashData = ConvertStringToHex(hashValue);
return hexHashData;
}
public static string HashData(string textToBeEncripted)
{
//Convert the string to a byte array
Byte[] byteDataToHash = System.Text.Encoding.Unicode.GetBytes(textToBeEncripted);
//Compute the MD5 hash algorithm
Byte[] byteHashValue = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(byteDataToHash);
return System.Text.Encoding.Unicode.GetString(byteHashValue);
}
public static string ConvertStringToHex(string asciiString)
{
string hex = "";
foreach (char c in asciiString)
{
int tmp = c;
hex += String.Format("{0:x2}", (uint) System.Convert.ToUInt32(tmp.ToString()));
}
return hex;
}
を、あなたは文字列「テスト」私は出力「5c82e9e41c7599f790ef1d774b7e6bf」 を取得し、これがあるために見ることができます私はPHP側
$a = "test";
$a = mb_convert_encoding($a, "UTF-16LE");
$a = md5($a);
echo $a;
に試みたが、PHPコードの値が何であるかを「c8059e2ec7419f590e79d7f1b774bfe6」.Whyが動作していませんか?
編集:C#のコードが間違っていると私はエンコーディングを変換することはあなたに別の答えを与えているものであると信じてい
「5c82e9e41c7599f790ef1d774b7e6bfは、」ここにしようとhttp://md5.gromweb.com/ –
098f6bcd4621d373cade4e832627b4f6 MD5ではないエンコーディングがらくたを失い、「テスト」の正しいMD5ハッシュです。 – Viezevingertjes
あなたは本当に 'System.Text.Encoding.Unicode.GetString(byteHashValue)'を使ってはいけません。ハッシュ値は、有効なUTFでないシーケンスを含むバイナリデータです。文字列として返す必要がある場合は、Base64エンコーディングまたは16進数のエンコーディングをバイト配列から直接取得する必要があります。 –