Home >Backend Development >C#.Net Tutorial >C# Calculate MD5 hash string
C# Calculating MD5 hash string
public static string CalculateMD5Hash(string input) { // step 1, calculate MD5 hash from input var md5 = MD5.Create(); byte[] inputBytes = Encoding.ASCII.GetBytes(input); byte[] hash = md5.ComputeHash(inputBytes); // step 2, convert byte array to hex string var sb = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("X2")); } return sb.ToString(); }
The above is the content of C# calculating MD5 hash string. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!