您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

33 行
932 B

  1. using System.Security.Cryptography;
  2. using System.Text;
  3. public class MD5Encryptor
  4. {
  5. /// <summary>
  6. /// 计算输入字符串的 MD5 哈希值。
  7. /// </summary>
  8. /// <param name="input">要计算哈希值的字符串。</param>
  9. /// <returns>返回 MD5 哈希值的十六进制字符串表示。</returns>
  10. public static string ComputeMD5Hash(string input)
  11. {
  12. // 使用 MD5 哈希算法
  13. using (MD5 md5 = MD5.Create())
  14. {
  15. // 将输入字符串转换为字节数组
  16. byte[] inputBytes = Encoding.UTF8.GetBytes(input);
  17. // 计算字节数组的哈希值
  18. byte[] hashBytes = md5.ComputeHash(inputBytes);
  19. // 将哈希字节数组转换为十六进制字符串
  20. StringBuilder sb = new StringBuilder();
  21. foreach (byte b in hashBytes)
  22. {
  23. sb.Append(b.ToString("x2")); // 将每个字节转换为两位的十六进制表示
  24. }
  25. return sb.ToString();
  26. }
  27. }
  28. }