加密方法
  • Create 创建加密实例
  • ComputeHash 进行加密
示例代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(GetMD5("123456"));
        }

        public static string GetMD5(string str)
        {
            // 创建MD5对象
            MD5 md5 = MD5.Create();
            // 将字符串转为字节数组
            byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(str);
            // 加密,返回一个加密好的字节数组
            byte[] md5Buffer = md5.ComputeHash(buffer);
            // 将字节数组转为字符串
            string newStr = "";
            for (int i = 0; i < md5Buffer.Length; i++)
            {
                newStr += md5Buffer[i].ToString("x");
            }
            return newStr;
        }
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
执行结果

【C#】MD5加密_字节数组