欢迎来到【一个大西瓜】的博客

不曾为梦想奋斗,拿什么去燃烧青春。有梦之人亦终将老去,但少年心气如昨。
太阳每一个时刻都同时是夕阳和朝阳,每天她沉入西边,意味着她同时从另一面土地升起。
扩大
缩小

MD5加密

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CaterCommon
{
    public partial class MD5Helper
    {
        public static string EncryptString(string str)
        {
            //utf-8,x2
            //创建对象的方法;构造方法,静态方法(工厂)
            MD5 md5 = MD5.Create();
            //将字符串转化成字节数组
            byte[] byteOld = Encoding.UTF8.GetBytes(str);
            //调用加密方法
            byte[] byteNew= md5.ComputeHash(byteOld);
            //将加密结果进行转换字符串
            StringBuilder sb = new StringBuilder();
            foreach (byte b in byteNew)
            {
                //将字符串转换成16进制的字符串,而且是恒占用两从头再来
                sb.Append(b.ToString("x2"));
            }
            //返回加密的字符串
            return sb;
        }
    }
}

posted on 2016-11-18 16:52  一个大西瓜咚咚咚  阅读(225)  评论(0编辑  收藏  举报

导航