MD5Tool.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //************************************************************************
  2. // author: yuzhengyang
  3. // date: 2018.3.27 - 2018.6.3
  4. // desc: MD5 工具
  5. // Copyright (c) yuzhengyang. All rights reserved.
  6. //************************************************************************
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Security.Cryptography;
  11. using System.Text;
  12. namespace Azylee.Core.DataUtils.EncryptUtils
  13. {
  14. public class MD5Tool
  15. {
  16. /// <summary>
  17. /// 给一个字符串进行MD5加密
  18. /// </summary>
  19. /// <param name="s">待加密字符串</param>
  20. /// <returns>加密后的字符串</returns>
  21. public static string Encrypt(string s)
  22. {
  23. string result = "";
  24. try
  25. {
  26. byte[] buffer = Encoding.UTF8.GetBytes(s);
  27. HashAlgorithm algorithm = MD5.Create();
  28. byte[] hashBytes = algorithm.ComputeHash(buffer);
  29. result = BitConverter.ToString(hashBytes).Replace("-", "");
  30. }
  31. catch { }
  32. return result;
  33. }
  34. }
  35. }