1234567891011121314151617181920212223242526272829303132333435363738 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web.Script.Serialization;
- namespace Ant.Core.Utils
- {
- public class MD5Helper
- {
- public static string MD5Hash(string input)
- {
- StringBuilder hash = new StringBuilder();
- MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider();
- byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input));
- for (int i = 0; i < bytes.Length; i++)
- {
- hash.Append(bytes[i].ToString("x2"));
- }
- return hash.ToString();
- }
- public static string MD5Hash<T>(T obj)
- {
- var jsonString = string.Empty;
- if (obj != null)
- {
- jsonString = new JavaScriptSerializer().Serialize(obj);
- }
- return MD5Hash(jsonString);
- }
- }
- }
|