asp.net暗号解読URL

4717 ワード

           Web  URL  (    )    。  :           ,      ID,URL  :http://localhost/mysystem/editAccounts.aspx?ID=2    
              ID 2,           2  ,      ID。    
              。    
       DEC  、     。    
   :Security.CS    
using System;    
using System.Security.Cryptography;    
using System.IO;    
using System.Text;    
namespace EIP.Framework    
{    
///    
/// Security      。    
/// Security   .NET         。    
/// CopyRight [email protected]@[email protected]    
///    
public class Security    
{    
string _QueryStringKey = "abcdefgh"; //URL      Key    
string _PassWordKey = "hgfedcba"; //PassWord  Key    
public Security()    
{    
//    
// TODO:                
//    
}    
///    
///   URL          
///    
///    
///    
public string EncryptQueryString(string QueryString)    
{    
return Encrypt(QueryString,_QueryStringKey);    
}    
///    
///   URL          
///    
///    
///    
public string DecryptQueryString(string QueryString)    
{    
return Decrypt(QueryString,_QueryStringKey);    
}    
///    
///           
///    
///    
///    
public string EncryptPassWord(string PassWord)    
{    
return Encrypt(PassWord,_PassWordKey);    
}    
///    
///           
///    
///    
///    
public string DecryptPassWord(string PassWord)    
{    
return Decrypt(PassWord,_PassWordKey);    
}    
///    
/// DEC         
///    
///    
///    
///    
public string Encrypt(string pToEncrypt,string sKey)    
{    
DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //      byte       
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);    
//byte[] inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);    
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //                 
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); //    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();    
}    
///    
/// DEC         
///    
///    
///    
///    
public string Decrypt(string pToDecrypt, string sKey)    
{    
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 = ASCIIEncoding.ASCII.GetBytes(sKey); //             ,    ,        
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);    
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());    
}    
///    
///                     
///    
///    
///    
///    
///    
public bool ValidateString(string EnString, string FoString, int Mode)    
{    
switch (Mode)    
{    
default:    
case 1:    
if (Decrypt(EnString,_QueryStringKey) == FoString.ToString())    
{    
return true;    
}    
else    
{    
return false;    
}    
case 2:    
if (Decrypt(EnString,_PassWordKey) == FoString.ToString())    
{    
return true;    
}    
else    
{    
return false;    
}    
}    
}    
}    
}    
  URL           KEY。  URL      :    
EIP.Framework.Security objSecurity = new EIP.Framework.Security();    
objSecurity.EncryptQueryString(''       '');    
  :objSecurity.DecryptQueryString(''       );