/// <summary> /// MD5加密算法 /// </summary> /// <param name="strPsw">用户名密码</param> /// <returns>加密后的结果</returns> public string MD5(string strPsw) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] data = Encoding.Default.GetBytes(strPsw);//将字符编码为一个字节序列 byte[] md5data = md5.ComputeHash(data);//计算data字节的哈希值 md5.Clear(); string str = ""; for (int i = 0; i < md5data.Length; i++) { str += md5data[i].ToString("x").PadLeft(2, '0'); } return str; }