MD5加密

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

namespace MD5加密
{
    class Program
    {
        static void Main(string[] args)
        {
            string s =GetMD5 ("123");
            //202cb962ac5975b964b7152d234b70
            //202cb962ac59075b964b07152d234b70这个是对的
            Console.WriteLine(s);
            double n = 123.123;
            Console.WriteLine(n.ToString("c"));//这里就把这个值转成了金钱
            Console.ReadKey();
        }

        public static string GetMD5(string str)
        {
            //创建MD5对象,MD5是抽象类,不能创建对象,只能用Create这种方法模拟出来一个
            MD5 md5 = MD5.Create();
            //开始加密
            //需要将字符串转换成字节数组
            byte[] buffer = Encoding.Default.GetBytes(str);
            //返回一个加密好的字节数组
            byte[] MD5buffer= md5.ComputeHash(buffer);

            //将字节数组转换成字符串
            //字节数组————字符串
            //将字节数组中每个元素按照指定的编码格式解析成字符串
            //直接将数组ToString();
            //将字节数组中的每个元素ToString();
            string strNew = "";
            for (int i = 0; i < MD5buffer .Length ; i++)
            {
                strNew += MD5buffer[i].ToString("x2");//这里加的x2是为了转格式,具体什么功能百度查ToString()里加什么会有什么功能
            }
            return strNew;
        }





    }

}