C#字符串转MD5


 1 using System;
2 using System.Text;
3 using System.Security.Cryptography;
4
5 namespace HashCode
6 {
7 class Program
8 {
9 public static string StrToMD5(string str)
10 {
11 byte[] data = Encoding.GetEncoding("GB2312").GetBytes(str);
12 MD5 md5 = new MD5CryptoServiceProvider();
13 byte[] OutBytes = md5.ComputeHash(data);
14
15 string OutString = "";
16 for (int i = 0; i < OutBytes.Length; i++)
17 {
18 OutString += OutBytes[i].ToString("x2");
19 }
20 // return OutString.ToUpper();
21 return OutString.ToLower();
22 }
23 static void Main(string[] args)
24 {
25 Console.WriteLine(StrToMD5("123456"));
26 Console.ReadKey();
27 }
28 }
29 }

输出结果:e10adc3949ba59abbe56e057f20f883e

作者:荒 木
出处:http://rophie.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

-----------------------------------------------

光阴溅落尘埃,翻飞着些许温凉如烟的旧梦,划过我迷离的眼。

原文地址:https://www.cnblogs.com/rophie/p/2378336.html