C#实现MD5算法

来源:互联网 发布:sql查询过滤重复记录 编辑:程序博客网 时间:2024/06/05 18:10
        using System.Collections;        using System.Security.Cryptography;        public class GetMD5        {            public string GetMD5Str(string str)            {                MD5 md5 = new MD5CryptoServiceProvider();                //将字符串转换为字节数组                byte[] fromData = System.Text.Encoding.Unicode.GetBytes(str);                //计算字节数组的哈希值                byte[] toData = md5.ComputeHash(fromData);                string byteStr = "";                for (int i = 0; i < toData.Length; i++)                {                    byteStr += toData[i].ToString("x");                }                return byteStr.Substring(0, 8);            }        }

0 0
原创粉丝点击