Md5.cs 686 B

123456789101112131415161718192021222324252627282930
  1. using System.Security.Cryptography;
  2. using System.Text;
  3. namespace CommonTool
  4. {
  5. public class Md5
  6. {
  7. public static string Encrypt(string str)
  8. {
  9. string pwd = string.Empty;
  10. MD5 md5 = MD5.Create();
  11. // 编码UTF8/Unicode 
  12. byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
  13. // 转换成字符串
  14. for (int i = 0; i < s.Length; i++)
  15. {
  16. //格式后的字符是小写的字母
  17. //如果使用大写(X)则格式后的字符是大写字符
  18. pwd = pwd + i.ToString("X");
  19. }
  20. return pwd;
  21. }
  22. }
  23. }