CSharp examples for System.Security.Cryptography:MD5
take any string and encrypt it using MD5 then return the encrypted data
using System.Text; using System.Security.Cryptography; public class Main{ /// <summary> /// take any string and encrypt it using MD5 then /// return the encrypted data /// </summary> /// <param name="data">input text you will enterd to encrypt it</param> /// <returns>return the encrypted text as hexadecimal string</returns> public static string GetMD5HashData(string data) {/*from www . ja v a2 s . c o m*/ //create new instance of md5 MD5 md5 = MD5.Create(); //convert the input text to array of bytes byte[] hashData = md5.ComputeHash(Encoding.ASCII.GetBytes(data)); //create new instance of StringBuilder to save hashed data StringBuilder returnValue = new StringBuilder(); //loop for each byte and add it to StringBuilder for (int i = 0; i < hashData.Length; i++) { returnValue.Append(hashData[i].ToString()); } // return hexadecimal string return returnValue.ToString(); } }