你好,我试图将此部分代码从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(?
类似但不完全是
更新:带BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
我有:1f3870 be274f6c49b3e31a0c6728957 f
当我使用md5("apple",false)时,我没有任何问题
试试这个:
var md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = Encoding.Default.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
var s = Encoding.Default.GetString(hash);
或者选择其他编码格式。