Converting a md5 hash byte array to a string

前端 未结 7 1536
余生分开走
余生分开走 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 13:54

    For anyone interested a Nuget package I created called CryptoStringify allows you to convert a string to a hashed string using a nice clean syntax, without having to play around with byte arrays:

    using (MD5 md5 = MD5.Create())
    {
        string strHashedPassword = md5.Hash(password);
    }
    

    It's an extension method on HashAlgorithm and KeyedHashAlgorithm so works on SHA1, HMACSHA1, SHA256 etc too.

    https://www.nuget.org/packages/cryptostringify

提交回复
热议问题