简体   繁体   中英

Diffrent result of md5 between php and c#

Hello I trying to convert this part code from php to c# with identical result:

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(?

Similar but not exactly

upd: with BitConverter.ToString(hashedBytes).Replace("-", "").ToLower(); I have got: 1f3870be274f6c49b3e31a0c6728957f

And I have not any problems when I use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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