Code: //метод для генерации md5 hash public string EncodePassword(string originalPassword) { //Declarations Byte[] originalBytes; Byte[] encodedBytes; MD5 md5; //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password) md5 = new MD5CryptoServiceProvider(); originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword); encodedBytes = md5.ComputeHash(originalBytes); //Convert encoded bytes back to a 'readable' string return BitConverter.ToString(encodedBytes); } ИМХО оптимальный метод.. И не забудь подключить using System.Security.Cryptography;
Code: using System.Security.Cryptography; public string MD5Hash(string instr) { string strHash = string.Empty; foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(instr))) { strHash += b.ToString("X2"); } return strHash; }