MD5Helper.cs 723 B

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