首页 > 其他 > 详细

MD5加密

时间:2017-02-12 16:53:15      阅读:170      评论:0      收藏:0      [点我收藏+]
 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Security.Cryptography;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 
 9 namespace ConsoleApplication6
10 {
11     class Program
12     {
13         static void Main(string[] args)
14         {
15             //张三 123
16             string str = "123";
17             string md5 = GetMd5(str);
18             Console.WriteLine(md5);
19             Console.ReadKey();
20         }
21         static string GetMd5(string str)
22         {
23             MD5 md5 = MD5.Create();//创建MD5实例对象
24             //开始加密
25             //将传入对象转换为字节数字
26             byte[] blist = Encoding.Default.GetBytes(str);
27             //将字节数组传入加密方法里面,返回一个字节数组
28             byte[] bmd5list = md5.ComputeHash(blist);
29             //将字节数组转换为string
30             StringBuilder sb = new StringBuilder();
31             for (int i = 0; i < bmd5list.Length; i++)
32             {
33                 sb.Append(bmd5list[i].ToString("x2"));//x表示将十进制转换为16进制。2表示每次都是两位数
34             }
35             return sb.ToString();
36         }
37     }
38 }

 

MD5加密

原文:http://www.cnblogs.com/wwz-wwz/p/6391111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!