class Program
{
static void Main(string[] args)
{
try
{
while (true)
{
Console.WriteLine("*********** 输入字符串进行 MD5 加密 按回车继续 ***************************************");
Console.WriteLine("请输入一个字符串");
string str = Console.ReadLine();
Console.WriteLine("加密过后的数据为");
Console.WriteLine(MD5Setting(str));
Console.WriteLine("");
}
}
catch (Exception ex)
{
Console.WriteLine("出错咯:" + ex.Message);
}
}
static string MD5Setting(string str)
{
StringBuilder sb = new StringBuilder();
using (MD5 md5 = MD5.Create())
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
byte[] md5Bytes = md5.ComputeHash(bytes);
for (int i = 0; i < md5Bytes.Length; i++)
{
sb.Append(md5Bytes[i].ToString("X2"));
}
}
return sb.ToString();
}
}