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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Salman BegRank #284 · 8.8K reputationPosted Apr 3, 2021, 8:04 AM EDT
Bohdan StupakRank #479 · 5.2K reputationPosted Nov 14, 2021, 7:07 AM EST
Michael Donald96 reputationPosted Dec 16, 2021, 4:54 AM EST
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#.
Dastaan188 reputationPosted Apr 3, 2021, 8:10 AM EDT