制作URL以GET方式提交的简单加密程序
首先我们用到的是
DESCryptoServiceProvider 类
对此微软给出的解释是
定义访问数据加密标准 (DES) 算法的加密服务提供程序 (CSP) 版本的包装对象。无法继承此类。
接下来是接受参数页面的方法:
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient; namespace Url加密
{
public partial class Content : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
GetDate();
}
} Byte[] byKey64 = { , , , , , , , };
Byte[] Iv64 = { , , , , , , , }; public string Decrypt(string strText)
{
Byte[] inputByteArray = new byte[strText.Length];
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey64, Iv64), CryptoStreamMode.Write);
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
} public string content = string.Empty; public void GetDate()
{
string sql = "SELECT * FROM [Info] WHERE [Id]=@id";
string ConStr = "Data Source=.;Initial Catalog=DBTest;User ID=sa;Password=123456";
SqlParameter para = new SqlParameter("@id", Decrypt(Request.QueryString["id"])); using (SqlConnection conn = new SqlConnection(ConStr))
{
conn.Open();
SqlCommand comm = new SqlCommand(sql.ToString(), conn);
comm.Parameters.Add(para);
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
content = reader["Details"].ToString();
}
reader.Close();
}
}
}
}
我用的是repeater的绑定方式
然后是传入ID参数的页面后台代码如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient; namespace Url加密
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
GetDate();
}
} Byte[] Iv64 = { , , , , , , , };
Byte[] byKey64 = { , , , , , , , };
public string Encrypt(string strText)
{
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
Byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey64, Iv64), CryptoStreamMode.Write);
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
} public string id = string.Empty; public void GetDate()
{
string sql = "SELECT * FROM [dbo].[Info]";
string ConStr="Data Source=.;Initial Catalog=DBTest;User ID=sa;Password=123456";
using(SqlConnection conn=new SqlConnection(ConStr))
{
conn.Open();
SqlCommand comm=new SqlCommand(sql.ToString(),conn);
DataSet dt = new DataSet();
SqlDataAdapter sdt = new SqlDataAdapter(sql.ToString(),conn);
sdt.Fill(dt);
this.Repeater1.DataSource = dt.Tables[];
this.Repeater1.DataBind();
}
}
}
}
他的前台参数绑定:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<a href="Content.aspx?id=<%#Encrypt(Eval("Id").ToString())%>"><%#Eval("Title") %></a>
</ItemTemplate>
</asp:Repeater>
请注意,对于ID转换成为字符串这一步很重要。以上就是我的个人心得了。希望有大神能够继续指教完善,同时也参考了网上的代码资料。对此表示感谢
制作URL以GET方式提交的简单加密程序的更多相关文章
- 8)post方式提交和简单那处理
带有htmll的代码: 实现简单的计算器 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...
- ASP.NET 最全的POST提交数据和接收数据 —— (1) 用url传参方式
//1.对象提交,字典方式 //接口方:public ActionResult GetArry(Car model) public void PostResponse() { HttpWebReque ...
- jquery.form.js实现将form提交转为ajax方式提交的使用方法
本文实例讲述了jquery.form.js实现将form提交转为ajax方式提交的方法.分享给大家供大家参考.具体分析如下: 这个框架集合form提交.验证.上传的功能. 这个框架必须和jquery完 ...
- Android 使用Post方式提交数据(登录)
在Android中,提供了标准Java接口HttpURLConnection和Apache接口HttpClient,为客户端HTTP编程提供了丰富的支持. 在HTTP通信中使用最多的就是GET和POS ...
- 解决ajax get post方式提交中文参数乱码问题
最近在工作中遇到,使用ajax get方式提交中文参数的时候出现乱码,通过上网搜索,总结出比较简单的两种解决方案: 第一种,由于tomcat默认的字符集是ISO-8859-1,修改Tomcat中的se ...
- jquery.form.js实现将form提交转为ajax方式提交的方法
本文实例讲述了jquery.form.js实现将form提交转为ajax方式提交的方法.分享给大家供大家参考.具体分析如下: 这个框架集合form提交.验证.上传的功能. 这个框架必须和jquery完 ...
- 温故而知新: 关于 js Form 方式提交的一些新认知
这里介绍的是通过js进行异步form提交,而不是表单Form Submit提交. 提交方式主要有以下两种: 参数为字符串方式的提交,如:a=b&c=d formData方式提交, 如:new ...
- 使用GET方式提交的表单遇到的问题
经常使用表单,一直使用的都是POST方式,POST将数据封装到请求体中,相对于GET安全一点:而POST处理中文编码问题也比GET简单(GET需要将URL编码,后台接受到后还需要解码).今天我想要使用 ...
- 采用DoGet方式提交中文,乱码产生原因分析及解决办法
前段时间某功能在测试机器上出现乱码,情况如下: 现象: 调试搜索功能时,通过doGet方法提交到后台的中文参数在本地和开发测试机器上为乱码(Action层),在测试人员测试机器 ...
随机推荐
- 轻量级RPC框架-motan
https://github.com/weibocom/motan/wiki/zh_quickstart#%E7%AE%80%E5%8D%95%E8%B0%83%E7%94%A8%E7%A4%BA%E ...
- Python-Anaconda练习candy算子用于边缘提取,再用hough变换检测直线边缘
img: 待检测的图像. threshold: 阈值,可先项,默认为10 line_length: 检测的最短线条长度,默认为50 line_gap: 线条间的最大间隙.增大这个值可以合并破碎的线条. ...
- Launch iCar Scan Android Scanner Support Bluetooth X431 iDiag Update Version
Autonumen.com release new Launch iCar Scan for Android,Launch iCarScan Bluetooth Scanner is update v ...
- my09_mysql指定时间点恢复之binlog start-position
场景描述 ********************************************* 在远程服务器做的全备并已经恢复,同时使用binlog server备份binlog 之后,删除了库 ...
- php rtrim的一个坑,很“二”的问题
一.背景: 做项目的时候遇到一种情况,商家的营业时间显示的问题,设计图上要求显示成:“星期一,星期二,星期三,星期四,星期五,星期六,星期天” 换句话说,就是营业星期勾哪个就显示哪个,类似下面这样: ...
- Win 10 Enable .net framework 3.5 error (Error code:0x800F081F )
在下面页面enable .net frramwork 3.5时,发生0x800F081F错误. 解决方案: 1. 在如下链接下载Win10 版的microsoft-windows-netfx3-ond ...
- vector 中需要注意的东西!
vector的erase方法注意点!!! C++11是这样的: iterator erase (const_iterator position); iterator erase (const_iter ...
- chrome 修改请求头的小工具
chrome 网上应用店中搜索 ModHeader
- Broken Keyboard (a.k.a. Beiju Text) UVA - 11988 (链表)
题目链接:https://vjudge.net/problem/UVA-11988 题目大意:输入一个字符串,输出在原本应该是怎么样的? 具体方法是 碰到' [ ' 回到最前面 碰到‘ ]’ 回 ...
- sublime text2 for mac 实现json格式化
问题描述: 网上拿下来的一大段json格式的字符串,放到sublime上格式化成json的标准格式 数据截图如下: 解决问题: 网络上搜了一下,大部分都是说要装pretty json插件 先来看看自己 ...