简体   繁体   English

php和c#之间md5的不同结果

[英]Diffrent result of md5 between php and c#

Hello I trying to convert this part code from php to c# with identical result: 您好,我试图将此零件代码从php转换为c#,结果相同:

PHP : PHP的

md5("apple", true) //result :8pѕ'OlIігg(•

C# : C#

    byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes("apple");
    byte[] hashedBytes =  MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
    return System.Text.Encoding.ASCII.GetString(hashedBytes); //result: 8p?'OlI??g(?

Similar but not exactly 相似但不完全相同

upd: with BitConverter.ToString(hashedBytes).Replace("-", "").ToLower(); 更新:使用BitConverter.ToString(hashedBytes).Replace("-", "").ToLower(); I have got: 1f3870be274f6c49b3e31a0c6728957f 我有:1f3870be274f6c49b3e31a0c6728957f

And I have not any problems when I use md5("apple", false) 而且当我使用md5(“ apple”,false)时我没有任何问题

Try this: 尝试这个:

 var md5 = System.Security.Cryptography.MD5.Create();
 byte[] inputBytes = Encoding.Default.GetBytes(input);
 byte[] hash = md5.ComputeHash(inputBytes);

 var s = Encoding.Default.GetString(hash);

or choose another Encoding format. 或选择其他编码格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM