MD5Encoding.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Security.Cryptography;
  5. using System.IO;
  6. namespace Com.Jpsoft.Hospital.Web.Common
  7. {
  8. public class MD5Encoding
  9. {
  10. public static string GetMD5_Str(string str)
  11. {
  12. MD5 md5 = new MD5CryptoServiceProvider();
  13. byte[] buffer = Encoding.ASCII.GetBytes(str);
  14. string md5Str = BitConverter.ToString(md5.ComputeHash(buffer)).Replace("-", "").ToLower();
  15. return md5Str;
  16. }
  17. public static byte[] GetMD5_Byte(string str)
  18. {
  19. return Encoding.ASCII.GetBytes(GetMD5_Str(str));
  20. }
  21. public static string GetMD5_Str(FileStream fs)
  22. {
  23. MD5 md5 = new MD5CryptoServiceProvider();
  24. string md5Str = BitConverter.ToString(md5.ComputeHash(fs)).Replace("-", "").ToLower();
  25. return md5Str;
  26. }
  27. public static byte[] GetMD5_Byte(FileStream fs)
  28. {
  29. return Encoding.ASCII.GetBytes(GetMD5_Str(fs));
  30. }
  31. }
  32. }