MD5Helper.cs 1011 B

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. using System.Web.Script.Serialization;
  8. namespace Ant.Core.Utils
  9. {
  10. public class MD5Helper
  11. {
  12. public static string MD5Hash(string input)
  13. {
  14. StringBuilder hash = new StringBuilder();
  15. MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider();
  16. byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input));
  17. for (int i = 0; i < bytes.Length; i++)
  18. {
  19. hash.Append(bytes[i].ToString("x2"));
  20. }
  21. return hash.ToString();
  22. }
  23. public static string MD5Hash<T>(T obj)
  24. {
  25. var jsonString = string.Empty;
  26. if (obj != null)
  27. {
  28. jsonString = new JavaScriptSerializer().Serialize(obj);
  29. }
  30. return MD5Hash(jsonString);
  31. }
  32. }
  33. }