Saturday, July 21, 2007

How to MD5 in .NET & Mono

Simple code: using System.Security.Cryptography; //... private readonly static MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); public static string CreatePasswordMD5(string password) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bs = System.Text.Encoding.UTF8.GetBytes(password); bs = md5.ComputeHash(bs); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in bs) { s.Append(b.ToString("x2").ToLower()); } return s.ToString(); } // Usage: Console.WriteLine(CreatePasswordMD5("p@ssw0rk!"));

No comments: