MD5Util.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace XYY.Core.Standard
  8. {
  9. public static class MD5Util
  10. {
  11. public static string Get(string str)
  12. {
  13. if (string.IsNullOrEmpty(str))
  14. {
  15. return null;
  16. }
  17. string str2 = "";
  18. var gb2312encode = Encoding.GetEncoding("GB2312");
  19. byte[] buffer = MD5.Create().ComputeHash(gb2312encode.GetBytes(str));
  20. for (int i = 0; i < buffer.Length; i++)
  21. {
  22. str2 = str2 + buffer[i].ToString("X2");
  23. }
  24. return str2;
  25. }
  26. public static string Get(string str, Encoding encoding)
  27. {
  28. string str2 = "";
  29. byte[] buffer = MD5.Create().ComputeHash(encoding.GetBytes(str));
  30. for (int i = 0; i < buffer.Length; i++)
  31. {
  32. str2 = str2 + buffer[i].ToString("X2");
  33. }
  34. return str2;
  35. }
  36. }
  37. }