Converting a md5 hash byte array to a string

前端 未结 7 1538
余生分开走
余生分开走 2021-01-31 13:28

How can I convert the hashed result, which is a byte array, to a string?

byte[] bytePassword = Encoding.UTF8.GetBytes(password);

using (MD5 md5 = MD5.Create())
         


        
相关标签:
7条回答
  • 2021-01-31 14:05

    Well as it is a hash, it has possibly values that cannot be shown in a normal string, so the best bet is to convert it to Base64 encoded string.

    string s = Convert.ToBase64String(bytes);
    

    and use

    byte[] bytes = Convert.FromBase64(s);
    

    to get the bytes back.

    0 讨论(0)
提交回复
热议问题