首页 > 代码库 > Md5 签名算法

Md5 签名算法

/// <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();
        }

Md5 签名算法