#region 对字符串的加密/解密
/// <summary>
/// 对字符串进行适应 ServU 的 MD5 加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string strServUPWD(string str)
{
string strResult = "";
strResult = Str.RandomSTR(2);
str = strResult + str;
str = NoneEncrypt(str,1);
str = strResult + str;
return str;
}
/// <summary>
/// 对字符串进行加密(不可逆)
/// </summary>
/// <param name="Password">要加密的字符串</param>
/// <param name="Format">加密方式,0 is SHA1,1 is MD5</param>
/// <returns></returns>
public static string NoneEncrypt(string Password,int Format)
{
string strResult = "";
switch( Format )
{
case 0 :
strResult = FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"SHA1");
break;
case 1 :
strResult = FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"MD5");
break;
default :
strResult = Password;
break;
}
return strResult;
}
/// <summary>
/// 对字符串进行加密
/// </summary>
/// <param name="Passowrd">待加密的字符串</param>
/// <returns>string</returns>
public static string Encrypt(string Passowrd)
{
string strResult = "";
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(Passowrd, true, 2);
strResult = FormsAuthentication.Encrypt(ticket).ToString();
return strResult;
}
/// <summary>
/// 对字符串进行解密
/// </summary>
/// <param name="Passowrd">已加密的字符串</param>
/// <returns></returns>
public static string Decrypt(string Passowrd)
{
string strResult = "";
strResult = FormsAuthentication.Decrypt(Passowrd).Name.ToString();
return strResult;
}
#endregion
/// <summary>
/// 对字符串进行适应 ServU 的 MD5 加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string strServUPWD(string str)
{
string strResult = "";
strResult = Str.RandomSTR(2);
str = strResult + str;
str = NoneEncrypt(str,1);
str = strResult + str;
return str;
}
/// <summary>
/// 对字符串进行加密(不可逆)
/// </summary>
/// <param name="Password">要加密的字符串</param>
/// <param name="Format">加密方式,0 is SHA1,1 is MD5</param>
/// <returns></returns>
public static string NoneEncrypt(string Password,int Format)
{
string strResult = "";
switch( Format )
{
case 0 :
strResult = FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"SHA1");
break;
case 1 :
strResult = FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"MD5");
break;
default :
strResult = Password;
break;
}
return strResult;
}
/// <summary>
/// 对字符串进行加密
/// </summary>
/// <param name="Passowrd">待加密的字符串</param>
/// <returns>string</returns>
public static string Encrypt(string Passowrd)
{
string strResult = "";
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(Passowrd, true, 2);
strResult = FormsAuthentication.Encrypt(ticket).ToString();
return strResult;
}
/// <summary>
/// 对字符串进行解密
/// </summary>
/// <param name="Passowrd">已加密的字符串</param>
/// <returns></returns>
public static string Decrypt(string Passowrd)
{
string strResult = "";
strResult = FormsAuthentication.Decrypt(Passowrd).Name.ToString();
return strResult;
}
#endregion

1745

被折叠的 条评论
为什么被折叠?



