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 str = "123";
string newStr=GetMd5(str);
Console.WriteLine(newStr);
}
public static string GetMd5(string pwd)
{
MD5 md5 = MD5.Create();
byte[] buffer = System.Text.Encoding.Default.GetBytes(pwd);
byte[] bufferMd5=md5.ComputeHash(buffer);
//string result = System.Text.Encoding.Default.GetString(bufferMd5);
//return result;
string str = "";
for (int i = 0; i < bufferMd5.Length; i++)
{
// str += bufferMd5[i].ToString();//十进制
//将10转换成16(8-16) (10-8)方法类似
str += bufferMd5[i].ToString("x");
}
return str;
}
}
} |