c# 如何计算字符串的md5值

2025-09-27 01:37:53

1、添加引用

using System.Security.Cryptography;

using System.Text;

2、编写如下代码

public static string GetMd5(string text)

 

        {

 

            StringBuilder sb = new StringBuilder();

 

            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())

 

            {

 

                byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(text));

 

                int length = data.Length;

 

                for (int i = 0; i < length; i++)

 

                {

 

                    sb.Append(data[i].ToString("x2"));

 

                }

 

                return (sb.ToString());

 

            }

 

        }

c# 如何计算字符串的md5值

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢