C# MD5

Posted on 2017-07-01 22:51  yacbo  阅读(193)  评论(0)    收藏  举报
            private static string GetMd5String(string msg)
            {
                StringBuilder sb = new StringBuilder();
                using(MD5 md5 = MD5.Create())
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(msg);

                    byte[] md5Byte = md5.ComputeHash(bytes);

                    for (int i = 0; i < md5Byte.Length; i++)
                    {
                        sb.Append(md5Byte[i].ToString("x2"));
                    }
                }
                return sb.ToString();
            }

  



博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3