简单md5加密
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Security.Cryptography; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace ConsoleApplication1 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 string s = getMD5("123"); 15 Console.WriteLine("{0}",s); 16 Console.ReadKey(); 17 } 18 public static string getMD5(string str) 19 { 20 MD5 md = MD5.Create(); 21 //将字符转换成字节数组 22 byte[] buffer=Encoding.Default.GetBytes(str); 23 //返回加密好的字节数组 24 byte[] mdbuffer=md.ComputeHash(buffer); 25 //转换字节数组为字符串 26 //1、将字节数组的每个元素按照指定编码格式解析成字符串 27 //Encoding.GetEncoding("utf-8").GetString(mdbuffer); 28 //2.将每个元素都Tostring 29 string Tostr = ""; 30 for (int i = 0; i < mdbuffer.Length; i++) 31 { 32 //将十进制转换成16进制 33 Tostr += mdbuffer[i].ToString("x"); 34 } 35 return Tostr; 36 } 37 38 } 39 }