MD5类(MD5Helper)
项目中经常需要使用到MD5来进行加密
代码:
namespace MyProject.Common { public class MD5Helper { /// <summary> /// 对字符串进行MD5运算 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string GetMd5String(string str) { MD5 md5 = MD5.Create(); byte[] buffer = Encoding.UTF8.GetBytes(str); byte[] md5Buffer = md5.ComputeHash(buffer); StringBuilder sb = new StringBuilder(); foreach (byte b in md5Buffer) { sb.Append(b.ToString("x2")); } md5.Clear(); return sb.ToString(); } } }
使用:直接调用静态方法,传入string