using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace _01MD5加密
{
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 = MD5.Create ();
//加密
//需要将字符数组转化成字节素组;
byte[] buff=Encoding .Default .GetBytes (str);
buff=md5.ComputeHash(buff);
//再将字节数组转化成字符串
//Encoding .Default .GetString (buff); //按照指定的编码格式解析层字符串
//直接将数组tostring;
//将字节数组每个元素tostring;
string st="";
for (int i = 0; i < buff.Length ; i++)
{
st+= buff[i].ToString("x2");
//十进制转换16进制不带0tostring("x")
//十进制转换16进制带0tostring ("x2")
}
return st;//Encoding .Default .GetString (buff);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace _01MD5加密
{
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 = MD5.Create ();
//加密
//需要将字符数组转化成字节素组;
byte[] buff=Encoding .Default .GetBytes (str);
buff=md5.ComputeHash(buff);
//再将字节数组转化成字符串
//Encoding .Default .GetString (buff); //按照指定的编码格式解析层字符串
//直接将数组tostring;
//将字节数组每个元素tostring;
string st="";
for (int i = 0; i < buff.Length ; i++)
{
st+= buff[i].ToString("x2");
//十进制转换16进制不带0tostring("x")
//十进制转换16进制带0tostring ("x2")
}
return st;//Encoding .Default .GetString (buff);
}
}
}