先引用两个命名空间
using System.Security.Cryptography; using System.Text;
以下是md5加密方法
/// <summary> /// md5加密--32位 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string md5jiami(string text) { byte[] result = Encoding.Default.GetBytes(text); MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); string s = BitConverter.ToString(output).Replace("-", ""); return s; }