Advertisement
MatthijsFontys

String to hash method

Dec 10th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System.Security.Cryptography; // Importing the hash algoritm PUT THIS WITH THE OTHER USINGS IN YOUR CODE !!!!
  2.  
  3.         private string passToHash(string pass)
  4.         {
  5.         // Creating the hash algorithm
  6.         HashAlgorithm algorithm = MD5.Create();
  7.         // Creating the output from the hash in bytes
  8.         byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(pass));
  9.  
  10.  
  11.         // converting bytes in hash to string
  12.         StringBuilder sb = new StringBuilder();
  13.         foreach (byte b in hash)
  14.         {
  15.             sb.Append(b.ToString("X2")); // X2 makes it an uppercase hexadecimal character
  16.         }
  17.  
  18.         return sb.ToString();
  19.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement