MD5Tool.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. byte[] buffer = Encoding.Default.GetBytes(s);
  25. HashAlgorithm algorithm = MD5.Create();
  26. byte[] hashBytes = algorithm.ComputeHash(buffer);
  27. result = BitConverter.ToString(hashBytes).Replace("-", "");
  28. return result;
  29. }
  30. }
  31. }