@manhng

Welcome to my blog!

Calculate a MD5 Hash from a String

August 17, 2021 09:11

MD5 Hash Generator (edit)

MD5 Class (System.Security.Cryptography) | Microsoft Docs

Hash.MD5 Property (System.Security.Policy) | Microsoft Docs

SoapHexBinary Constructor (System.Runtime.Remoting.Metadata.W3cXsd2001) | Microsoft Docs (HAY HAY HAY)

c# - Calculate a MD5 hash from a string - Stack Overflow

C# Create A MD5 Hash From A String | C# Examples (csharpexamples.com)

Good

 using System.Security.Cryptography;
using System.Text;

public static string CreateMd5Hash(string input)
{
// Step 1, calculate MD5 hash from input
MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);

// Step 2, convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}

Best (HAY HAY HAY)

 using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Security.Cryptography;
using System.Text;

public static string GetMd5Hash(string input)
{
using (var md5 = MD5.Create())
{
byte[] computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
return new SoapHexBinary(computedHash).ToString();
}
}

Categories

Recent posts