可直接在控制台程序运行:
using System;
using System.Security.Cryptography;
using System.Text;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string input = "123456";//请输入要加密的字符串
string encryptedString = GetMd5Hash(input);
Console.WriteLine("加密后的字符串为:" + encryptedString);
Console.ReadKey();
}
// 计算字符串的 MD5 哈希值
static string GetMd5Hash(string input)
{
using (MD5 md5Hash = MD5.Create())
{
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
builder.Append(data[i].ToString("x2"));
}
return builder.ToString();
}
}
}
}