/// <summary> /// 把字符转换成MD5 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string GetMD5Hash(String str) { //把字符串转换成字节数组 byte[] buffer = Encoding.Default.GetBytes(str); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); //md5加密 byte[] cryptBuffer = md5.ComputeHash(buffer); string s = ""; //把每一个字节 0-255,转换成两位16进制数 for (int i = 0; i < cryptBuffer.Length; i++) { //大X转黄的是大写字母,小X转换的是小写字母 s += cryptBuffer[i].ToString("x2"); } return s; }
转自:http://www.nbcoder.net/thread-271-1-1.html
时间: 2024-10-06 06:59:02