/*----------------------------------------------------------------
    Copyright (C) 2017 Senparc
    
    ÎÄ¼þÃû£ºMD5UtilHelper.cs
    ÎÄ¼þ¹¦ÄÜÃèÊö£º»ñÈ¡´óÐ´µÄMD5Ç©Ãû½á¹û
    
    
    ´´½¨±êÊ¶£ºSenparc - 20150313
    
    ÐÞ¸Ä±êÊ¶£ºSenparc - 20150313
    ÐÞ¸ÄÃèÊö£ºÕûÀí½Ó¿Ú
----------------------------------------------------------------*/

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

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

		/// <summary>
        /// »ñÈ¡´óÐ´µÄMD5Ç©Ãû½á¹û
		/// </summary>
		/// <param name="encypStr"></param>
		/// <param name="charset"></param>
		/// <returns></returns>
		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 = BitConverter.ToString(outputBye);
			retStr = retStr.Replace("-", "").ToUpper();
			return retStr;
		}
	}
}
