Posted By

housecor on 12/02/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

franksmile0310
Rak


MD5 hash method


 / Published in: C#
 

  1. /// <summary>
  2. /// Hash an input string and return the hash as a 32 character hexadecimal string.
  3. /// </summary>
  4. /// <param name="input"></param>
  5. /// <returns></returns>
  6. public string MD5(string input)
  7. {
  8. byte[] textBytes = System.Text.Encoding.Default.GetBytes(input);
  9. try
  10. {
  11. System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
  12. cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
  13. byte[] hash = cryptHandler.ComputeHash(textBytes);
  14. string ret = "";
  15. foreach (byte a in hash)
  16. {
  17. if (a < 16)
  18. ret += "0" + a.ToString("x");
  19. else
  20. ret += a.ToString("x");
  21. }
  22. return ret;
  23. }
  24. catch
  25. {
  26. throw;
  27. }
  28. }

Report this snippet  

You need to login to post a comment.