Hi,
I want to encrypt a sting in md5 with chechsum value (asp.net c#). please help me.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Michael DonaldPosted Dec 16, 2021, 9:54 AM
I will be showing a simple code that can be used to encrypt a text to its MD5 hash.
Code Block :
public string CalculateMD5Hash(string input)
{
// To calculate MD5 hash from an input string
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
// convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
//to make hex string use lower case instead of uppercase add parameter “X2”
sb.Append(hash[i].ToString(“X2”));
}
return sb.ToString();
}
For Example if you pass a string to the Method like
String hashResult = CalculateMMD5Hash(“abcdefghijklmnopqrstuvwxyz”);
The returning string will be : C3FCD3D76192E4007DFB496CCA67E13B.
This was a simple code block that would help in creating an MD5 hash resulting string in C#.
Bohdan StupakPosted Nov 14, 2021, 12:07 PM
DastaanPosted Apr 3, 2021, 12:10 PM
Salman BegPosted Apr 3, 2021, 12:04 PM