MD5 加密
方式一:
#region 加密 public static string GetMD5(string myString) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); byte[] targetData = md5.ComputeHash(fromData); string byte2String = null; for (int i = 0; i < targetData.Length; i++) { byte2String += targetData[i].ToString("x2"); } return byte2String; } #endregion
方式二:(https://md5jiami.51240.com/ 和这个网址可以查询的MD5加密方式一样,和泰铭短信的加密方式一样)
应该是比较标准的MD5加密了
public static string Encrypt(string encryptString) { var md5 = new MD5CryptoServiceProvider(); var result = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(encryptString))); result = result.Replace("-", ""); return result.ToLower(); }
#region 加密 public static string GetMD5(string myString) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); byte[] targetData = md5.ComputeHash(fromData); string byte2String = null; for (int i = 0; i < targetData.Length; i++) { byte2String += targetData[i].ToString("x2"); } return byte2String; } public static string Encrypt(string encryptString) { var md5 = new MD5CryptoServiceProvider(); var result = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(encryptString))); result = result.Replace("-", ""); return result.ToLower(); } public static string MD5Encrypt(string strText) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] result = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(strText)); return System.Text.Encoding.Default.GetString(result); } public static string MD5M(string str) { MD5 md5 = MD5.Create(); byte[] result = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); return System.Text.Encoding.Default.GetString(result); //MD5 md = new d; //return "123"; } public static string MD5E(string str) { byte[] arry1 = Encoding.ASCII.GetBytes(str); MD5 m = new MD5CryptoServiceProvider(); byte[] arry2 = m.ComputeHash(arry1, 0, arry1.Length); return Convert.ToBase64String(arry2); } #endregion
/// <summary> /// 加密 /// </summary> /// <param name="encryptString">加密字符串</param> /// <returns></returns> public static string Encrypt(string encryptString) { var md5 = new MD5CryptoServiceProvider(); var result = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(encryptString)), 4, 8);//16位 result = result.Replace("-", ""); return result.ToLower(); }