地址栏传值加密

来源:百度知道 编辑:UC知道 时间:2024/07/02 08:48:42
例:输入http://localhost/qiyes/shownews.asp?id=1
如果这样输入http://localhost/qiyes/shownews.asp?id=1'或者id=任意字符,都会得出
Microsoft VBScript 编译器错误 错误 '800a03f6'
缺少 'End'
/iisHelp/common/500-100.asp,行242
Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e21'
ODBC 驱动程序不支持所需的属性。
/qiyes/shownews.asp,行7
怎样避免?请大家指教!

在传递的时候 将ID加密 获取时候 解密
使用 DES .

如:

/// <summary>
/// 加密。注意:sKey输入密码的时候,必须使用英文字符,区分大小写,且字符数量是8个,不能多也不能少,否则出错。
/// </summary>
public static string Encrypt(string pToEncrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//把字符串放到byte数组中
//原来使用的UTF8编码,我改成Unicode编码了,不行
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
//byte[] inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);

//建立加密对象的密钥和偏移量
//原文使用ASCIIEncoding.ASCII方法的GetBytes方法
//使得输入密码必须输入英文文本
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),CryptoStreamMode.Write);
//Write the byte array into the crypto stream
//(It will end up in the memory stream)