MD5加密
程序员文章站
2022-03-14 19:53:02
...
MD5加密
命名空间:
using System.Security.Cryptography;
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 = "123456";
string md5 = GetMD5(s);
Console.WriteLine(md5);
Console.ReadLine();
}
private static string GetMD5(string s)
{
MD5 md = MD5.Create();
byte[] buffer = Encoding.GetEncoding("GBK").GetBytes(s);
byte[] mdBuffer = md.ComputeHash(buffer);
//字节数组转字符串
//将字节数组的每个元素按照指定的编码转成字符串输出
//直接进行ToString
//将字节数组中的每一个元素进项ToString
string res = "";
for (int i = 0; i < mdBuffer.Length; i++)
{
res += mdBuffer[i].ToString("x2");
}
return res;
//e10adc3949ba59abbe56e057f20f883e
}
}
}