Created
May 11, 2020 05:31
-
-
Save xbotter/cc757f4fb5b22f15acc143c859866d76 to your computer and use it in GitHub Desktop.
C# MD5 String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetMd5String(string input) | |
{ | |
using (MD5 md5Hash = MD5.Create()) | |
{ | |
// Convert the input string to a byte array and compute the hash. | |
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); | |
// Create a new Stringbuilder to collect the bytes | |
// and create a string. | |
StringBuilder sBuilder = new StringBuilder(); | |
// Loop through each byte of the hashed data | |
// and format each one as a hexadecimal string. | |
for (int i = 0; i < data.Length; i++) | |
{ | |
sBuilder.Append(data[i].ToString("x2")); | |
} | |
// Return the hexadecimal string. | |
return sBuilder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.md5