Advertisement
Guest User

SHA512

a guest
Aug 20th, 2014
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. string SHA512(string strToEncrypt){
  2.         System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding ();
  3.         byte[] bytes = ue.GetBytes (strToEncrypt);
  4.  
  5.         //encrypt bytes
  6.         System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create ();
  7.         byte[] hashBytes = sha512.ComputeHash (bytes);
  8.  
  9.         //convert hashed bytes back to utf8 encoding
  10.         string hashString = "";
  11.  
  12.         for (int i = 0; i < hashBytes.Length; i++) {
  13.             hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');       
  14.         }
  15.  
  16.         return hashString.PadLeft(32, '0');
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement