Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. ```csharp
  2. private static string GetHash(string text)
  3. {
  4. MD5 MD5 = new MD5CryptoServiceProvider();
  5. byte[] asciiBytes = Encoding.ASCII.GetBytes(text);
  6. return GetHexString(MD5.ComputeHash(asciiBytes));
  7. }
  8.  
  9. private static string GetHexString(byte[] bytes)
  10. {
  11. string text = string.Empty;
  12. for (int i = 0; i < bytes.Length; i++)
  13. {
  14. byte b = bytes[i];
  15. int n, n1, n2;
  16. n = b;
  17. n1 = n & 15;
  18. n2 = (n >> 4) & 15;
  19. if (n2 > 9)
  20. {
  21. text += ((char) (n2 - 10 + (int) 'A')).ToString();
  22. }
  23. else
  24. {
  25. text += n2.ToString();
  26. }
  27.  
  28. if (n1 > 9)
  29. {
  30. text += ((char) (n1 - 10 + (int) 'A')).ToString();
  31. }
  32. else
  33. {
  34. text += n1.ToString();
  35. }
  36.  
  37. if ((i + 1) != bytes.Length && (i + 1) % 2 == 0)
  38. {
  39. text += "-";
  40. }
  41. }
  42. return text;
  43. }
  44. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement