62,046
社区成员
发帖
与我相关
我的任务
分享
#region DES 加密/解密
private static byte[] key = ASCIIEncoding.ASCII.GetBytes("99999999");
private static byte[] iv = ASCIIEncoding.ASCII.GetBytes("11111111");
/// <summary>
/// DES加密。
/// </summary>
/// <param name="pToEncrypt">输入字符串。</param>
/// <returns>加密后的字符串。</returns>
public static string DESEncrypt(string pToEncrypt)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //把字符串放到byte数组中
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
//byte[] inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);
des.Key = key; //建立加密对象的密钥和偏移量
des.IV = iv; //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
MemoryStream ms = new MemoryStream(); //使得输入密码必须输入英文文本
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
/// <summary>
/// DES解密。
/// </summary>
/// <param name="pToDecrypt">输入字符串。</param>
/// <returns>解密后的字符串。</returns>
public static string DESDecrypt(string pToDecrypt)
{
//MemoryStream ms = null;
//CryptoStream cs = null;
//StreamReader sr = null;
//DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//try
//{
// ms = new MemoryStream(Convert.FromBase64String(inputString));
// cs = new CryptoStream(ms, des.CreateDecryptor(key, iv), CryptoStreamMode.Read);
// sr = new StreamReader(cs);
// return sr.ReadToEnd();
//}
//finally
//{
// if (sr != null) sr.Close();
// if (cs != null) cs.Close();
// if (ms != null) ms.Close();
//}
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for (int x = 0; x < pToDecrypt.Length / 2; x++)
{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = key; //建立加密对象的密钥和偏移量
des.IV = iv; //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder(); //建立StringBuild对象,CreateDecrypt使用的是流对象,必须把解密后的文本变成流对象
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
catch (Exception)
{
//throw;
return "";
}
}
#endregion
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
///URLRewriter 的摘要说明
/// </summary>
public class URLRewriter : System.Web.UI.Page, IHttpModule
{
public URLRewriter()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(this.ReUrl_BeginRequest);
context.EndRequest += new EventHandler(this.ReUrl_EndRequest);
}
private void ReUrl_BeginRequest(object sender, EventArgs e)
{
HttpContext Context = ((HttpApplication)sender).Context;
Context.Response.Buffer = true;
Context.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1.0);
Context.Response.Expires = 0;
Context.Response.CacheControl = "no-cache";
_url = Context.Request.Url.ToString().ToLower();
_url = _url.Replace("localhost", "111111.axpx");
// string urlquest = Context.Request.Url.Query;
// string url = Context.Request.Url.AbsolutePath;
Context.Response.Redirect(_url);
}
public void Dispose()
{
}
protected string _url = "";
protected string strUrl
{
get { return _url; }
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void ReUrl_EndRequest(object sender, EventArgs args)
{
}
/// <summary>
///
/// </summary>
/// <param name="Context"></param>
public void ProcessRequest(HttpContext Context)
{
}
/// <summary>
/// 实现“IHttpHandler”接口所必须的成员
/// </summary>
/// <value></value>
public bool IsReusable
{
get { return false; }
}
}