C#生成md5

        /// <summary>
        /// 计算md5
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string CalcMD5(string str)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            using (MD5 md5 = MD5.Create())
            {
                byte[] md5Bytes = md5.ComputeHash(buffer);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < md5Bytes.Length; i++)
                {
                    sb.Append(md5Bytes[i].ToString("x2"));//X2时,生成字母大写MD5
                }
                return sb.ToString();
            }
        }

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页