MD5Helper.cs 820 B

1234567891011121314151617181920212223242526272829
  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. namespace XdCxRhDW.Core
  8. {
  9. public class MD5Helper
  10. {
  11. public static string StrToMD5(string str)
  12. {
  13. MD5 md5 = MD5.Create();
  14. byte[] c = System.Text.Encoding.Default.GetBytes(str);
  15. byte[] b = md5.ComputeHash(c);//用来计算指定数组的hash值
  16. //将每一个字节数组中的元素都tostring,在转成16进制
  17. string newStr = null;
  18. for (int i = 0; i < b.Length; i++)
  19. {
  20. newStr += b[i].ToString("X2"); //ToString(param);//传入不同的param可以转换成不同的效果
  21. }
  22. return newStr;
  23. }
  24. }
  25. }