byte[] inputBytes = Encoding.UTF8.GetBytes("The quick brown fox jumps over the lazy dog"); var md5 = new MD5CryptoServiceProvider(); byte[] hashBytes = md5.ComputeHash(inputBytes); string hashString = BitConverter.ToString(hashBytes).Replace("-", ""); Console.WriteLine(hashString);
using (var md5 = MD5.Create()) { byte[] inputBytes = Encoding.UTF8.GetBytes("The quick brown fox jumps over the lazy dog"); byte[] hashBytes = md5.ComputeHash(inputBytes); string hashString = BitConverter.ToString(hashBytes).Replace("-", ""); Console.WriteLine(hashString); }Output: "9E107D9D372BB6826BD81D3542A419D6" Another way to use the MD5 algorithm is shown in this example. We use the static Create method of the MD5 class to create a new instance and then call the ComputeHash method in a using statement. This ensures that the object is properly disposed of when the block is exited. Package library: This functionality is provided by the .NET Framework, which is included in the standard library of C#. No additional package library is required.