- /// <summary>
- /// method to generate a MD5 hash of a string
- /// </summary>
- /// <param name="strToHash">string to hash</param>
- /// <returns>hashed string</returns>
- public string GenerateMD5(string str)
- {
- MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
- byte[] byteArray = Encoding.ASCII.GetBytes(str);
- byteArray = md5.ComputeHash(byteArray);
- string hashedValue = "";
- foreach (byte b in byteArray)
- {
- hashedValue += b.ToString("x2");
- }
- return hashedValue;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1305201512575.html
来源: http://www.codesnippet.cn/detail/1305201512575.html