////// 获取文件的md5摘要 /// /// 文件流 ///MD5摘要结果 public static string GetAbstractToMD5(Stream sFile) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] result = md5.ComputeHash(sFile); StringBuilder sb = new StringBuilder(32); for (int i = 0; i < result.Length; i++) { sb.Append(result[i].ToString("x").PadLeft(2, '0')); } return sb.ToString(); } ////// 获取文件的md5摘要 /// /// 文件流 ///MD5摘要结果 public static string GetAbstractToMD5(byte[] dataFile) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] result = md5.ComputeHash(dataFile); StringBuilder sb = new StringBuilder(32); for (int i = 0; i < result.Length; i++) { sb.Append(result[i].ToString("x").PadLeft(2, '0')); } return sb.ToString(); } ////// 签名字符串 /// /// 需要签名的字符串 /// 密钥 /// 编码格式 ///签名结果 public static string Md5Sign(string prestr, string key, string _input_charset) { StringBuilder sb = new StringBuilder(32); prestr = prestr + key; MD5 md5 = new MD5CryptoServiceProvider(); byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(prestr)); for (int i = 0; i < t.Length; i++) { sb.Append(t[i].ToString("x").PadLeft(2, '0')); } return sb.ToString(); } ////// 验证签名 /// /// 需要签名的字符串 /// 签名结果 /// 密钥 /// 编码格式 ///验证结果 public static bool Md5Verify(string prestr, string sign, string key, string _input_charset) { string mysign = Md5Sign(prestr, key, _input_charset); if (mysign == sign) { return true; } else { return false; } }