using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class EncryptPassword: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(encryptPassword("0490", "SHA1") + "," + encryptPassword("0490", "MD5")+"<br/>");
Label1.Text = encryptPassword("0490","");
Response.Write(Decode(Label1.Text));
}
/// <summary>
/// SHA1,MD5加密
/// </summary>
/// <param name="PassWords"></param>
/// <param name="passFormat"></param>
/// <returns></returns>
string encryptPassword(string PassWords, string passFormat)
{
string Encrypt = string.Empty;
if (passFormat == "SHA1")
{
Encrypt = FormsAuthentication.HashPasswordForStoringInConfigFile(PassWords, passFormat);
}
else if (passFormat == "MD5")
{
Encrypt = FormsAuthentication.HashPasswordForStoringInConfigFile(PassWords, passFormat);
}
return Encrypt;
}
/// <summary>
/// 按位或运算加密
/// </summary>
/// <param name="PassWords"></param>
/// <returns></returns>
string Encode(string PassWords)
{
string Encrypt = string.Empty;
for (int i = 0; i < PassWords.Length; i++)
{
Encrypt += (char)(PassWords[i] + 50 - 1 * 3); //此处为自己提供的密钥
}
return Encrypt;
}
/// <summary>
/// 按位或运算解密
/// </summary>
/// <param name="PassWords"></param>
/// <returns></returns>
string Decode(string PassWords)
{
string Encrypt = string.Empty;
for (int i = 0; i < PassWords.Length; i++)
{
Encrypt += (char)(PassWords[i] - 50 + 1 * 3);//此处为自己提供的密钥
}
return Encrypt;
}
}