[C#] C# 里的MD5 算法代码片段 →→→→→进入此内容的聊天室

来自 , 2020-05-06, 写在 C#, 查看 110 次.
URL http://www.code666.cn/view/49986430
  1. using System;
  2.  
  3. public string CreateMD5Hash (string input)
  4. {
  5.    // Use input string to calculate MD5 hash
  6.    MD5 md5 = System.Security.Cryptography.MD5.Create();
  7.    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes (input);
  8.    byte[] hashBytes  = md5.ComputeHash (inputBytes);
  9.  
  10.    // Convert the byte array to hexadecimal string
  11.    StringBuilder sb = new StringBuilder();
  12.    for (int i = 0; i < hashBytes.Length; i++)
  13.    {
  14.        sb.Append (hashBytes[i].ToString ("X2"));
  15.        // To force the hex string to lower-case letters instead of
  16.        // upper-case, use he following line instead:
  17.        // sb.Append(hashBytes[i].ToString("x2"));
  18.    }
  19.    return sb.ToString();
  20. }
  21.  
  22.  
  23. //csharp/4151

回复 "C# 里的MD5 算法代码片段"

这儿你可以回复上面这条便签

captcha