1 using System; 2 using System.Security.Cryptography; 3 using System.Text; 4 5 namespace Sam.OA.Common 6 { 7 /// <summary> 8 /// Md5帮助类 9 /// </summary> 10 public class Md5Helper 11 { 12 /// <summary> 13 /// 对字符串进行Md5运算,不可逆 14 /// </summary> 15 /// <param name="str">加密字符串</param> 16 /// <returns></returns> 17 public static string GetMd5String(string str) 18 { 19 try 20 { 21 MD5 md5 = MD5.Create(); 22 byte[] buffer = Encoding.UTF8.GetBytes(str); 23 byte[] md5Buffer = md5.ComputeHash(buffer); 24 StringBuilder sb = new StringBuilder(); 25 foreach (byte b in md5Buffer) 26 { 27 sb.Append(b.ToString("x2")); 28 } 29 md5.Clear(); 30 return sb.ToString(); 31 } 32 catch (Exception ex) 33 { 34 throw ex; 35 } 36 } 37 } 38 }
原文:https://www.cnblogs.com/chenyanbin/p/11312034.html