using System;
using System.Security.Cryptography;
using System.Text;

namespace tenpay
{
	/// <summary>
	/// MD5Util µÄÕªÒªËµÃ÷¡£
	/// </summary>
	public class MD5Util
	{
		public MD5Util()
		{
			//
			// TODO: ÔÚ´Ë´¦Ìí¼Ó¹¹Ôìº¯ÊýÂß¼­
			//
		}

		/** »ñÈ¡´óÐ´µÄMD5Ç©Ãû½á¹û */
		public static string GetMD5(string encypStr, string charset)
		{
			string retStr;
			MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvider();

			//´´½¨md5¶ÔÏó
			byte[] inputBye;
			byte[] outputBye;

			//Ê¹ÓÃGB2312±àÂë·½Ê½°Ñ×Ö·û´®×ª»¯Îª×Ö½ÚÊý×é£®
			try
			{
				inputBye = Encoding.GetEncoding(charset).GetBytes(encypStr);
			}
			catch (Exception ex)
			{
				inputBye = Encoding.GetEncoding("GB2312").GetBytes(encypStr);
			}
			outputBye = m5.ComputeHash(inputBye);

			retStr = System.BitConverter.ToString(outputBye);
			retStr = retStr.Replace("-", "").ToUpper();
			return retStr;
		}
	}
}
