1 public static string Md5Sum(string strToEncrypt) 2 { 3 System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding(); 4 byte[] bytes = ue.GetBytes(strToEncrypt); 5 6 // encrypt bytes 7 System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); 8 byte[] hashBytes = md5.ComputeHash(bytes); 9 10 // Convert the encrypted bytes back to a string (base 16) 11 string hashString = ""; 12 13 for (int i = 0; i < hashBytes.Length; i++) 14 { 15 hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0'); 16 } 17 18 return hashString.PadLeft(32, '0'); 19 }