using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace mdstr
{
internal class Program
{
static void Main(string[] args)
{
string s = getmd5("123");
Console.WriteLine(s);
Console.ReadKey();
}
public static string getmd5(string str) {
MD5 mD5 = MD5.Create();
//字符串转换成字节数组
byte[] buffer = Encoding.GetEncoding("gbk").GetBytes(str);
//加密
byte[] md5buff=mD5.ComputeHash(buffer);
//return Encoding.GetEncoding("gbk").GetString(md5buff);
string strnew = "";
//字节数组转换为string
for (int i = 0; i < md5buff.Length; i++)
{
//每一份转换成两位16进制
strnew+= md5buff[i].ToString("x2");
}
return strnew;
}
}
}