1
你好,我想這部分代碼PHP轉換爲C#有相同的結果:指出錯誤結果
PHP:
md5("apple", true) //result :8pѕ'OlIігg(•
C#:
byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes("apple");
byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
return System.Text.Encoding.ASCII.GetString(hashedBytes); //result: 8p?'OlI??g(?
類似但不完全是
upd:與BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
我得到了:1f3870 be274f6c49b3e31a0c6728957f
,我沒有任何問題,當我使用MD5( 「蘋果」,假)
這有幫助嗎? http://stackoverflow.com/questions/5821677/md5-hashing-does-not-match-in-c-sharp-and-php –
你正在打印原始的二進制垃圾,其中一些字符被誤解,由您的輸出環境解釋。例如一些字節序列LOOK就像是多字節字符。你的md5非常好,這只是一個輸出/顯示問題。 –
副節點:'MD5CryptoServiceProvider'是'IDisposable',因此應該*丟棄* –