using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Encryption 的摘要说明
/// </summary>
public class Encryption
{
	public Encryption()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    /// <summary>
    /// encrypting string《加密》
    /// </summary>
    /// <returns></returns>
    public static string Encrypt(string Password)
    {
        string str = "";
        FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(Password, true, 2);
        str = FormsAuthentication.Encrypt(ticket).ToString();
        return str;
    }

    /// <summary>
    /// encrypting string《SHA1 or MD5加密》
    /// </summary>
    /// <param name="Password">encrypting string</param>
    /// <param name="Format">format,0 is SHA1,1 is MD5</param>
    /// <returns></returns>
    public static string pwencrypt(string Password, int Format)
    {
        string str = "";
        switch (Format)
        {
            case 0:
                str = FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "SHA1");
                break;
            case 1:
                str = FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "MD5");
                break;
        }
        return str;
    }

    /// <summary>
    /// decrypt string《解密》
    /// </summary>
    /// <param name="Passowrd">encrypted string</param>
    /// <returns></returns>
    public static string Decrypt(string Passowrd)
    {
        string str = "";
        str = FormsAuthentication.Decrypt(Passowrd).Name.ToString();
        return str;
    }

 

}
