using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic;
using System.Security.Cryptography;
namespace CenturyBar
{
class MD5
{
//创建getMd5方法以获得userPwd的Md5值
public static string getMd5(string userPwd)
{
//获取userPwd的byte类型数组
byte[] byteUserPwd = Encoding.UTF8.GetBytes(userPwd);
//实例化MD5CryptoServiceProvider
MD5CryptoServiceProvider myMd5 = new MD5CryptoServiceProvider();
// byte类型数组的值转换为 byte类型的Md5值
byte[] byteMd5UserPwd = myMd5.ComputeHash(byteUserPwd);
//将byte类型的Md5值转换为字符串
string strMd5Pwd = "";
for (int i = 0; i < byteMd5UserPwd.Length; i++)
{
strMd5Pwd += byteMd5UserPwd[i].ToString("X");
//大写的X,得到的strMd5Pwd是大写字母和数字组成的字符串
//小写的x,得到的strMd5Pwd是小写字母和数字组成的字符串
}
//返回Md5字符串
return strMd5Pwd;
}
}
}