MD5Tool.cs 777 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. namespace Y.Utils.DataUtils.EncryptUtils
  7. {
  8. public class MD5Tool
  9. {
  10. /// <summary>
  11. /// 给一个字符串进行MD5加密
  12. /// </summary>
  13. /// <param name="s">待加密字符串</param>
  14. /// <returns>加密后的字符串</returns>
  15. public static string Encrypt(string s)
  16. {
  17. string result = "";
  18. byte[] buffer = Encoding.Default.GetBytes(s);
  19. HashAlgorithm algorithm = MD5.Create();
  20. byte[] hashBytes = algorithm.ComputeHash(buffer);
  21. result = BitConverter.ToString(hashBytes).Replace("-", "");
  22. return result;
  23. }
  24. }
  25. }