/// <summary>
        /// MD5签名
        /// </summary>
        /// <param name="prestr">待签名字符串</param>
        /// <param name="key">密钥</param>
        /// <param name="charset">编码</param>
        /// <returns>签名</returns>
        public static string Sign(string prestr, string key, string charset = "utf-8")
        {
            prestr = prestr + "&key=" + key;
            var sb = new StringBuilder(32);
            MD5 md5 = new MD5CryptoServiceProvider();
            var arr = md5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(prestr));
            foreach (var b in arr)
            {
                sb.Append(b.ToString("x").PadLeft(2, '0'));
            }
            return sb.ToString();
        }

posted on 2016-11-22 10:30  菜鸟Only  阅读(1752)  评论(1编辑  收藏  举报