Posted on 2017-09-18 09:54
viery 阅读(80)
评论(0) 编辑 收藏 所属分类:
.net
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 MD5Test
9 {
10 class Program
11 {
12 static void Main(string[] args)
13 {
14 Console.WriteLine(getMd5("123"));
15 Console.ReadKey();
16 }
17
18
19 public static string getMd5(string str)
20 {
21
22 MD5 md5 =MD5.Create();
23 byte[] bytes=Encoding.UTF8.GetBytes(str);
24 byte[] s=md5.ComputeHash(bytes);
25 StringBuilder sb = new StringBuilder();
26 for (int i = 0; i < s.Length; i++)
27 {
28 sb.Append(s[i].ToString("x2"));
29 }
30 return sb.ToString();
31 }
32 }
33 }
34