日期:2014-05-18 浏览次数:20763 次
using System; using System.Text; using System.Security.Cryptography; class MD5Encrypt { static string Encrypt(string InString) { MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); byte[] bs = Encoding.UTF8.GetBytes(InString);//源字符串转换为字节数组 bs = x.ComputeHash(bs);//加密返回Hash值数组 StringBuilder s = new StringBuilder(); foreach (byte b in bs)//循环生成字符串 { s.Append(b.ToString("x2").ToUpper()); } string ECode = s.ToString();//加密后的字符串 string E1 = ECode.Substring(0, 3);//前三位 string E2 = ECode.Substring(3, s.Length-3); return E1+"-"+E2; } static void Main() { Console.WriteLine(Encrypt("ABCDE")); Console.ReadLine(); } }