Advertisement
D3vBl4ck

Untitled

Jul 26th, 2017
21,883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System.Text;
  2. using System.Security.Cryptography;
  3.  
  4. namespace CryptoLib
  5. {
  6.   public static class Encryptor
  7.   {
  8.     public static string MD5Hash(string text)
  9.     {
  10.       MD5 md5 = new MD5CryptoServiceProvider();
  11.      
  12.       //compute hash from the bytes of text
  13.       md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));
  14.  
  15.       //get hash result after compute it
  16.       byte[] result = md5.Hash;
  17.  
  18.       StringBuilder strBuilder = new StringBuilder();
  19.       for (int i = 0; i < result.Length; i++)
  20.       {
  21.         //change it into 2 hexadecimal digits
  22.         //for each byte
  23.         strBuilder.Append(result[i].ToString("x2"));
  24.       }
  25.  
  26.       return strBuilder.ToString();
  27.     }
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement