Posted By

tomaszsimon on 12/23/09


Tagged

md5 checksum


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

natsuki
emregulcan


MD5 checksum returned as a string


 / Published in: C#
 

URL: http://www.spiration.co.uk/post/1203/MD5%20in%20C%23%20-%20works%20like%20php%20md5%28%29%20example

  1. public static string MD5(string password)
  2. {
  3. byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
  4. try
  5. {
  6. System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
  7. cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
  8. byte[] hash = cryptHandler.ComputeHash(textBytes);
  9. string ret = "";
  10. foreach (byte a in hash)
  11. {
  12. ret += a.ToString("x2");
  13. }
  14. return ret.ToUpper(); ;
  15. }
  16. catch
  17. {
  18. throw;
  19. }
  20. }

Report this snippet  

You need to login to post a comment.