public class MD5 { /// <summary> /// 32位MD5加密 /// </summary> /// <param name="str">待加密字符</param> /// <returns></returns> public static string GetMD5_32(string str) { //32位加密 if (string.IsNullOrEmpty(str)) { return ""; } else { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5"); } } /// <summary> /// 16位MD5加密(取32位加密的9~25字符) /// </summary> /// <param name="str">待加密字符</param> /// <returns></returns> public static string GetMD5_16(string str) { if (string.IsNullOrEmpty(str)) { return ""; } else { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16); } } }