md5加密
支持.netcore5
using System;
using System.Security.Cryptography;
namespace MyApp.HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(MD5Encrypt("123456"));
Console.WriteLine("Hello World!");
}
/// <summary>
/// 给一个字符串进行MD5加密
/// </summary>
/// <param name="strText">待加密字符串</param>
/// <returns>加密后的字符串</returns>
public static string MD5Encrypt(string strText)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] fromData = System.Text.Encoding.Default.GetBytes(strText);
byte[] targetData = md5.ComputeHash(fromData);
string byte2String = null;
for (int i=0; i<targetData.Length; i++)
{
byte2String += targetData[i].ToString("x");
}
return byte2String;
}
}
}
















